FACTORIAL {using loops}
USING {FOR LOOPS}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact=1;
printf("enter numbers = ");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
(fact=fact*i);
}
{
printf("%d",fact);
}
getch();
}
Output
enter numbers = 5
120
USING {WHILE LOOPS}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact=1;
printf("enter numbers = ");
scanf("%d",&n);
while(n>0)
{
(fact=fact*n);
n--;
}
{
printf("%d",fact);
}
getch();
}
Comments
Post a Comment