TO FIND FACTORIAL OF A NUMBER USING C PROGRAM





Code 1:
1. C code for factorial of a number
2. C program to find the factorial of a given number
3. Factorial program in c using while loop
4. Factorial program in c without using recursion

#include<stdio.h>
int main(){
  int i=1,f=1,num;

  printf("Enter a number: ");
  scanf("%d",&num);

  while(i<=num){
      f=f*i;
      i++;
  }

  printf("Factorial of %d is: %d",num,f);
  return 0;
}

Sample output:
Enter a number: 5
Factorial of 5 is: 120

Code 2:
1. Factorial program in c using for loop
2. Simple factorial program in c
3. C program to calculate factorial

#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;
}

Code 3:
1. Factorial program in c using pointers
2. How to calculate factorial in c
3. Factorial program in c language

#include<stdio.h>

void findFactorial(int,int *);
int main(){
  int i,factorial,num;

  printf("Enter a number: ");
  scanf("%d",&num);

  findFactorial(num,&factorial);
  printf("Factorial of %d is: %d",num,*factorial);

  return 0;
}

void findFactorial(int num,int *factorial){
    int i;

    *factorial =1;

    for(i=1;i<=num;i++)
      *factorial=*factorial*i;
}

Code 4:
1. Factorial program in c using function
2. C program to find factorial of a number

#include<stdio.h>

int findFactorial(int);
int main(){
  int i,factorial,num;

  printf("Enter a number: ");
  scanf("%d",&num);

  factorial = findFactorial(num);
  printf("Factorial of %d is: %d",num,factorial);

  return 0;
}

int findFactorial(int num){
    int i,f=1;

    for(i=1;i<=num;i++)
      f=f*i;

     return f;
}
Sample output:
Enter a number: 8
Factorial of 8 is: 40320

Code 5:
1. Factorial series in c

#include<stdio.h>
int main(){
  long f=1;
  int i,num,min,max;

  printf("Enter the minimum range: ");
  scanf("%d",&min);

  printf("Enter the maximum range: ");
  scanf("%d",&max);

  printf("Factorial series in given range: ");
  for(num=min;num<=max;num++){
    f=1;

    for(i=1;i<=num;i++)
      f=f*i;

    printf("%ld ",f);
  }

  return 0;
}

Sample output:
Enter the minimum range: 1
Enter the maximum range: 10
Factorial series in given range: 1 2 6 24 120 720 5040 40320 362880 3628800


Algorithm:


Factorial value

Factorial of number is defined as:
Factorial (n) = 1*2*3 … * n
For example: Factorial of 5 = 1*2*3*4*5 = 120
Note: Factorial of zero = 1 




10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

53 comments:

Anonymous said...

thankzz a lot for this program!!

Anonymous said...

Thanx a lot for this program.

Priyanka Muddalapuram said...

really thanks for this program.
this is very helpfull for me to learn how to write programs without any teacher's help.
thanks alot...........

yvsrao said...

thaks a lot...

vidyalakshmi said...

thank you

Anonymous said...

thx bro really helped me :)

Anonymous said...

thnks a lott..

Anonymous said...

thanks for this code !!!!

Anonymous said...

nice one dude!!!!!1

Anonymous said...

I got an idea 2 write a program myself by seeing this page

Anonymous said...

i got idea 2 write program.. thanks...

Unknown said...

thank u very much

Unknown said...

thanks you

Anonymous said...

thanx dude

asmith said...

plz send me ans.

program to linked list
single linked list and double linked list with insert, delete items.

Anonymous said...

tenk u for ur program....jejeje

shalbin said...

Thak you for publishing c programs,all are very useful.......

Anonymous said...

abid javed....

yr program perfect nia hy.......

Shreekharane said...

Thank you so much for the programs, it was really helpful, :)

Balbir said...

Thanks for usefull ideas

Ammu said...

Thank u very much..I am practising my own programs

Anonymous said...

thank u very much to this program..........

Anonymous said...

factorial using two variables?

sujit kumar said...

superb.......!!!

dauphin said...

Thank you guys that's really helpful for me! You saved me!!:)

Unknown said...

Guys can uplz post a prog for finding factorial for numbers above 10 as the range of 11! exceeds int and so here is the logic but i am not able to code it
example 5!=120
A[0]=0,A[1]=2,A[2]=1
6!=720=6*5!
6*A[0]=0;6*A[1]=12;6*A[2]=6;
now removing the 1 from A[1]=12 i.e A[1]=2;and adding it to A[2]i.e A[2]=7 and then reversing the array
i.e A[0]=7,A[1]=2,A[2]=0 and displaying it i.e 6!=720 similarly for 7!=5040 u can try but using this logic plz code the program

Anonymous said...

can u provide program of factorial with arguments nd no return value

Priyanka kumari said...

To find the factorial of very large number like 1000 go through following link:
Factorial of big numbers by c program

Priyanka kumari said...

Check the Code1

Unknown said...

thanks

Unknown said...

i need ur helps how can i write a program in c++ to take input from user and it must show it as asterisk using for or while loop.plz

Anand said...

The recursive solution of the above problem(ques 1).

#include
main()
{
int num;
scanf("%d\n",&num);
printf("%d",fact(num));
}
int fact(int num)
{
if(num == 1)
return 1;
return fact(num-1)*num;
}

Anonymous said...

can I get the "stack" program in c now plzzzzzzz

Anonymous said...

Can I get the program palindrome using stack

Anonymous said...

have u any gw basic program and some short information about it

Anonymous said...

Facebook page for programming concepts is
Codecommunity

Unknown said...

//factorial of large numbers
#include
#include
void calculate(int*,int);
void print(int*,int);
#define max 10000
//int max =100000000000;
int main()
{ int i,j,a[max],n;
printf("enter the no to find factorial\n\n");
scanf("%d",&n);
a[0]=1;
for(i=1;i<=max;i++)
a[i]=0;

for(i=1;i<=n;i++)
{for(j=0;j=10)
{rev=a[k]%10;
p=a[k]/10;
a[k+1]+=p;
a[k]=rev;
}


//print(a,i);
}


void print(int *a,int i)
{
// printf(" ipp is %d",i);

int l,c=0;
printf("factorial of %d is\n\n",i);
for(l=max-1;l>=0;l--)
{ if((a[l]==0)&&(c==0))
continue;
printf("%d",a[l]);
c=1;

}
printf("\n\n");
}

Anonymous said...

how to print factorial of a number when user enters 52 input will be between 1 and 100
answer is not coming right....

Unknown said...

hmm

Amar verma said...

this programe is not enough

brian mk said...

thanks pretty much guys

brian mk said...

thanks guys pretty much

brian mk said...

really cool thinkin

Unknown said...

Write a Program to add and subtract two array matrices.please

Alok said...



Factorial of a number



Write a program to find the factorial of a number using functions.

Function Specification:

int factorial(int n)

The function accepts a int and returns an int.



Input Format:

Input consists of 1 integer.



Output Format:

Output consists of a single integer. Refer sample output for formatting details.



Sample Input:

3



Sample Output:

6

Alok said...

can u help me for this

Unknown said...

its nice code.
http://www.techcrashcourse.com/2014/10/c-program-find-factorial-of-number.html

Unknown said...

i need ur helps how can i write a program in c++ to take input from user and it must show it as asterisk using for or while loop.plz

Unknown said...

can you write a reverse program of factorial like 120=5! and 720=6!

Unknown said...

can you write a reverse program of factorial like 120=5! and 720=6!

snapcout said...

nice program for beginner , we can also find factorial of any number by using for loop
http://scanfcode.com/c-program-find-factorial-number/

Danish Equbal said...

Your Factorial Program is wrong because the factorial of 1 is 1 but it shows factorial of 1 is 2.please correct it

indicoderz said...

thank you