Sunday 1 September 2013

Write a c program to get factorial of given number.



Write a c program to get factorial of given number.

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

0 comments:

Post a Comment

 

C Programming Language Interview Questions and Answers Tutorial for beginners. Copyright 2013 All Rights Reserved