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.

closed how to find the factorial of the given number?

+4 votes
asked Nov 2, 2019 by lokesh (160 points)
closed Nov 16, 2019 by Admin
closed with the note: Since it is answered.

8 Answers

+1 vote
answered Nov 2, 2019 by Gurpreet Singh (170 points)
//  C program to find factorial

#include<stdio.h>

int main(){

int fact=1,n;

printf("Enter the element : ");

scanf("%d",&n);

for(int i=1;i<=n;i++){

fact=fact*i;

}
printf("Factorial of %d is %d",n,fact);

return 0;

}
commented Dec 2, 2024 by Siva Chandru (120 points)
program to find factorial

#include<stdio.h>

int main(){

int fact=1,n;

printf("Enter the element : ");

scanf("%d",&n);

for(int i=1;i<=n;i++){

fact=fact*i;

}
printf("Factorial of %d is %d",n,fact);

return 0;

}
0
votes
answered Nov 2, 2019 by Akhil Menon M (280 points)
#include<stdio.h>

void main()

{
    int a,b,result,i;

    
    
    
    
    
    
    
    result=1;
    printf("Enter the number finding the factorial \n");
    scanf("%d",&a);
    
    for(i=1;i<=a;i++)
    {
        result=result*i;
    }
    
    printf("The answer is %d",result);
    
    
}
0
votes
answered Nov 2, 2019 by anonymous
#include <stdio.h>

int fact(int n)
{
    if(n != 1)
        return n*fact(n-1);
    else return 1;
}

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d", fact(n));
    return 0;
}
commented Nov 14, 2019 by kanan (100 points)
yeah this is correct answer. I also wanted to write exactly this code and I saw that you have written before me
0
votes
answered Nov 2, 2019 by sk varsha
def fact(n)

            if n==0:

                     return 1

            else:

                     return n*fact(n-1)

           print(fact(0))

           print(fact(5))
commented Nov 3, 2019 by gameforcer (3,010 points)
edited Nov 3, 2019 by gameforcer
#alternative example with math.factorial():


import math

print(math.factorial(5))
0
votes
answered Nov 7, 2019 by dheeraj (1,090 points)
reshown Nov 7, 2019 by dheeraj
a=int(input('enter the number for what factorial u want'))
fact=a
while a>1:
    a=a-1
    fact=fact*a
print(fact)

output:

enter the number for what factorial u want5
120
+1
vote
answered Nov 10, 2019 by X.S.
#include<iostream>

using namespace std;

int main()

{

int n,s=1;  // unsigned long long n,s=1;

cin>>n;

for(int i=1;i<=n;i++)

{

s*=i;  // s=s*i;

}

cout<<s;

}
0
votes
answered Nov 12, 2019 by Tyler (160 points)
  int x, num, prod, x2, num2, prod2, x3, num3, prod3, a, b, c, t, t2, t3, t4,
    t5, y, p;
  char ans;
  {
    cout << "What is your number? ";
    cin >> num;
    prod = 1;
    for (x = num; x >= 1; x--)
      prod = prod * x;
    cout << "The factorial of the number is " << prod;

}

All the other ints are for my entire program lol

0
votes
answered Nov 15, 2019 by prathyusha01 (140 points)
//c program to find factorial

#include<stdio.h>

int main()

{

      int i=1,n,fact=1;

      printf("enter the value of n");

      scanf("%d",&n);

      while(i<=n)

      {

               fact=fact * i;

               i++;

      }

       printf("factorial of %d = %d",fact,n);

}

 
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.
ads via Carbon
Find unique fonts designed by Creators just like you. Explore Now.
ads via Carbon
Send feedback
Snow Theme by Q2A MarketPowered by Question2Answer
0 votes
answered Nov 2, 2019 by Akhil Menon M (280 points)
#include<stdio.h>

void main()

{
    int a,b,result,i;

    
    
    
    
    
    
    
    result=1;
    printf("Enter the number finding the factorial \n");
    scanf("%d",&a);
    
    for(i=1;i<=a;i++)
    {
        result=result*i;
    }
    
    printf("The answer is %d",result);
    
    
}
0 votes
answered Nov 2, 2019 by anonymous
#include <stdio.h>

int fact(int n)
{
    if(n != 1)
        return n*fact(n-1);
    else return 1;
}

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d", fact(n));
    return 0;
}
commented Nov 14, 2019 by kanan (100 points)
yeah this is correct answer. I also wanted to write exactly this code and I saw that you have written before me
0 votes
answered Nov 2, 2019 by sk varsha
def fact(n)

            if n==0:

                     return 1

            else:

                     return n*fact(n-1)

           print(fact(0))

           print(fact(5))
commented Nov 3, 2019 by gameforcer (3,010 points)
edited Nov 3, 2019 by gameforcer
#alternative example with math.factorial():


import math

print(math.factorial(5))
0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
reshown Nov 7, 2019 by dheeraj
a=int(input('enter the number for what factorial u want'))
fact=a
while a>1:
    a=a-1
    fact=fact*a
print(fact)

output:

enter the number for what factorial u want5
120
+1 vote
answered Nov 10, 2019 by X.S.
#include<iostream>

using namespace std;

int main()

{

int n,s=1;  // unsigned long long n,s=1;

cin>>n;

for(int i=1;i<=n;i++)

{

s*=i;  // s=s*i;

}

cout<<s;

}
0 votes
answered Nov 12, 2019 by Tyler (160 points)

  int x, num, prod, x2, num2, prod2, x3, num3, prod3, a, b, c, t, t2, t3, t4,
    t5, y, p;
  char ans;
  {
    cout << "What is your number? ";
    cin >> num;
    prod = 1;
    for (x = num; x >= 1; x--)
      prod = prod * x;
    cout << "The factorial of the number is " << prod;

}

All the other ints are for my entire program lol

0 votes
answered Nov 15, 2019 by prathyusha01 (140 points)

//c program to find factorial

#include<stdio.h>

int main()

{

      int i=1,n,fact=1;

      printf("enter the value of n");

      scanf("%d",&n);

      while(i<=n)

      {

               fact=fact * i;

               i++;

      }

       printf("factorial of %d = %d",fact,n);

}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...