Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
13. Write a program to find the factorial of a given number.
/*
File: Prgrm13.c
Author: Aditya Saini
Date: Sept 30, 2019
Description: Program to find the factorial of a given number.
*/
#include <stdio.h>
int main (void)
{
int number;
int factorial;
int i;
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
int factorial;
int i;
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
//Finding the factorial.
for (factorial = 1, i = number; i >= 1; i--)
{
factorial = factorial * i;
}
//Output the result
printf ("Factorial of %d is %d.", number, factorial);
{
factorial = factorial * i;
}
//Output the result
printf ("Factorial of %d is %d.", number, factorial);
};
Output
Input number: 5
Factorial of 5 is 120.
No comments:
Post a Comment
Please do not post spam links.