factorial c program using for loop
#include<stdio.h>
int main(){
int i,f=1,num;
printf("Enter a number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
printf("Factorial of %d is: %d",num,f);
return 0;
}
factorial c program using for loop
#include<stdio.h>
int main(){
int i,f=1,num;
printf("Enter a number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
printf("Factorial of %d is: %d",num,f);
return 0;
}
factorial of a given number in c
//Factorial of a given number
#include <stdio.h>
//This function returns factorial of the number passed to it
long int factorialOf(int number){
long int factorial = 1;
while(number){
factorial*=number;
number-=1;
}
return factorial;
}
int main(void) {
int n;
printf("Find factorial of \n");
scanf("%d",&n);
printf("\nThe factorial of %d is %ld",n,factorialOf(n));
return 0;
}
c code factorial function
#include <stdio.h>
int fact(int);
void main()
{
int no,factorial;
printf("Enter a number to calculate it's factorial\n");
scanf("%d",&no);
factorial=fact(no);
printf("Factorial of the num(%d) = %d\n",no,factorial);
//printf("Factorial of the num(%d) = %d\n",no,fact(no));//another way of calling a function//comment above two lines if you want to use this
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
factorial program in c using function
#include <stdio.h>
int fact (num1);
void main ()
{
int num,ret;
printf ("Enter the number: ");
scanf("%d",&num);
ret = fact(num);
printf("\nthe factorial of %d is %d\n",num,ret);
}
int fact(num1)
{
int i, f=1;
for(i=1; i<=num1; i++)
{
f = f * i;
}
return f;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us