Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

factorial of number

0 votes
asked Sep 23, 2017 by Anny Prakash (120 points)

4 Answers

0 votes
answered Sep 23, 2017 by nick
commented Oct 24, 2017 by Владимир Шевляков (100 points)
Important notice is that with the int type of variables program can give a factorial only for numbers from 0 to 12.
0 votes
answered Nov 5, 2017 by Ruturaj khandare
#include <stdio.h>

int main()

{

int a;

int b,c;

printf("Enter a number: ");

scanf("%d", &a);

c=a;

if(a==0)

{

printf("Factorial %d = 1 \n",a);

}

     if(a<0)

printf("Factorial of negative number doesn't exists.\n");

     if(a>0)

    {

      b=1;

    while(a>0)

    {

    

      b= b*a;

    a--;

     }

    printf("Factorial of %d = %d\n",c,b );

   }

}
+1 vote
answered Nov 9, 2017 by DreamWorld26

#include <stdio.h>
long int multiplyNumbers(int n);

int main()
{
    int n;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    printf("Factorial of %d = %ld", n, multiplyNumbers(n));
    return 0;
}
long int multiplyNumbers(int n)
{
    if (n >= 1)
        return n*multiplyNumbers(n-1);
    else
        return 1;
}

0 votes
answered Nov 13, 2017 by sai yaddalapudi (300 points)
#include <stdio.h>
int fact(int n)
{
    if(n==0)
    return 1;
    else if(n==1)
    return 1;
    else
    return n*fact(n-1);
}
int main()
{
    printf("ENter a num\t");
    int n;
    scanf("%d",&n);
    int p=fact(n);
    printf("Fact =%d",p);
   
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...