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.

42 comments:

  1. thankzz a lot for this program!!

    ReplyDelete
  2. Love u Tintu7/22/08, 10:53 PM

    Thanx a lot for this program.

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

    ReplyDelete
  4. thx bro really helped me :)

    ReplyDelete
  5. thnks a lott..

    ReplyDelete
  6. thanks for this code !!!!

    ReplyDelete
  7. nice one dude!!!!!1

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

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

    ReplyDelete
  10. thanx dude

    ReplyDelete
  11. plz send me ans.

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

    ReplyDelete
  12. tenk u for ur program....jejeje

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

    ReplyDelete
  14. abid javed....

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

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

    ReplyDelete
  16. Thanks for usefull ideas

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

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

    ReplyDelete
  19. factorial using two variables?

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

    ReplyDelete
  21. 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

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

      Delete
    2. //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");
      }

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

    ReplyDelete
  23. 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

    ReplyDelete
  24. 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;
    }

    ReplyDelete
  25. can I get the "stack" program in c now plzzzzzzz

    ReplyDelete
  26. Can I get the program palindrome using stack

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

    ReplyDelete
  28. For discussing c programs and logics like this facebook page.

    https://www.facebook.com/CodeCommunity4Codes

    ReplyDelete
  29. Facebook page for programming concepts is
    Codecommunity

    ReplyDelete
  30. Thanks for the post. Because of this post I have been able to find the factorial of the number without using function. Please review it.
    http://ioeengineer.blogspot.com/2014/02/to-find-factorial-of-entered-number.html

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

    ReplyDelete