Answers for "c factor number"

C
3

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;
}
Posted by: Guest on June-15-2020
1

c code factorial function

#include <stdio.h>
 
int fact(int);
 
void main()
{
 int no,factorial;
 
  	printf("Enter a number to calculate it's factorialn");
  	scanf("%d",&no);
  	factorial=fact(no);
    printf("Factorial of the num(%d) = %dn",no,factorial);
//printf("Factorial of the num(%d) = %dn",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;
}
Posted by: Guest on April-17-2021

Code answers related to "C"

Browse Popular Code Answers by Language