spoj.pl/problems/FCTRL2/
its a simple factorial problem and i dont see whats the error in my code..but i get wrong answer everytime i try....even for a few other problems i got such errors...till now only the first problem has actually worked for me....any idea where im going wrong?

#include<iostream>
#include<stdio.h>
using namespace std;
int factorial(int m)
{
    return (m==1?1:m*factorial(m-1));
}
int main()
{
    int t,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&m);
        printf("%d\n",factorial(m));
    }
    return 0;
}
  • created

    Oct '08
  • last reply

    Oct '08
  • 1

    reply

  • 102

    views

  • 2

    users

  • 1

    link

You should always take careful note of the input limits and make sure you test your program on boundary cases. In other words, try the largest possible input of 100 - you output 0.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 37 29d

Want to read more? Browse other topics in C and C++ or view latest topics.