#include<stdio.h>
#include<conio.h>
int main()
{
int i,fact=1,n;
clrscr();
printf("Enter the number: ");
scanf("%d",&n); // takes input for calculating the factorial
for(i=1;i<=n;i++)
/* here i=1 and n=5 so 1<=5 its true so the loop is started
{
fact=fact*i; // fact=1 i=1 so fact*i gives 1 and store this into the fact
/* after that i is increased by 1 and compute the previous line until i<=n gives a false value */
printf("%d! = %d\n",i,fact);
}
getch();
return 0;
}

what is clrscr()?
ReplyDeleteits clear the screen every time before show the result
Delete