Object: - Write a program and algorithm to find the factorial of a given number.
Algorithm:-
Algorithm:-
Step (1):- Start
Step (2):- Declare the variable n, fact, i ;
Step (3):- initialize variable
fact ← 1
Step (4):- Read the value of n
For i ← 1 to n and i is incremented by 1
Step (5):- fact=fact * i
Step (6):- Display fact
Step (7):- Stop
Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int n, fact=1, i;
clrscr();
printf("Enter the Number");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
fact=fact*i;
}
printf("%d",fact);
getch();
}
--------------------------------------------------------------------------------
Output:-
Enter the Number
5
120
--------------------------------------------------------------------------------
0 Comments:
Post a Comment