Program:
(gcc)
#include<stdio.h>
main ()
{
int i,n,fact=1;
printf("Enter the number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact = fact*i;
}
printf("Factorial=%d\n",fact);
}
Output:
nn@linuxmint ~ $ gcc c1.c
nn@linuxmint ~ $ ./a.out
Enter the number: 5
Factorial=120
nn@linuxmint ~ $
(Turboc)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,f=1;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
if(n<0)
printf("sorry.......");
else if(n<=1)
printf("Factorial =1.");
else
{
for(i=1;i<=n;i++)
{
f*=i;
}
printf("Factorial=%d",f);
}
getch();
}
(gcc)
#include<stdio.h>
main ()
{
int i,n,fact=1;
printf("Enter the number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact = fact*i;
}
printf("Factorial=%d\n",fact);
}
Output:
nn@linuxmint ~ $ gcc c1.c
nn@linuxmint ~ $ ./a.out
Enter the number: 5
Factorial=120
nn@linuxmint ~ $
(Turboc)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,f=1;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
if(n<0)
printf("sorry.......");
else if(n<=1)
printf("Factorial =1.");
else
{
for(i=1;i<=n;i++)
{
f*=i;
}
printf("Factorial=%d",f);
}
getch();
}
Enroll now in our Best Mern Stack Course In South Delhi to explore the world of full-stack web development. Develop a strong foundation in the MERN technology stack and stay ahead in your web development journey.
ReplyDelete