Computer Science, asked by sathudr12, 6 months ago

write a program to find the factorial of a number​

Answers

Answered by roshni2262
1

Answer:

C program to find factorial of a number

  • long factorial(int);
  • int main() { int n;
  • printf("Enter a number to calculate its factorial\n"); scanf("%d", &n);
  • printf("%d! = %ld\n", n, factorial(n));
  • return 0; }
  • long factorial(int n) { int c; long r = 1;
  • for (c = 1; c <= n; c++) r = r * c;
  • return r; }
Answered by sougatap57
0

Answer:

The language used:-

1.C++

2.C

Explanation:

1)C++

#include <iostream>

using namespace std;

int main()

{

  int n1,fact=1,i;

  cout<<"enter the range of the factorial";

  cin>>n1;

  for(i=1;i<=n1;i++)

  {

      fact=fact*i;

  }

   cout<<"the factorial is ="<<fact;  

  return 0;

}

Output

enter the range of the factorial 6

the factorial is = 720

2)c program

#include<stdio.h>

int main()

{

int n,fact=1,t;

printf(" enter the range of the factorial");

scanf("%d",&n);

for(t=1;t<=n;t++)

{

fact=fact*t;

}

printf("the factorial=%d",fact);

return 0;

}

Output

enter the range of the factorial 5

the factorial=120

Similar questions