( not sure abt syntax.... of c language)int sol;
sol=1;
if (factno<1)
exit();
for(i=factno;i>0;i--)
{sol=sol*i;
}
printf("The factorial of %d is %d ",factno,sol);
#include <stdio.h>
#include <conio.h>
void main()
{
int product=1,a,i;
printf("enter the no.\n");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
product=product*i;
}
printf("factorial is %d",product);
getch();
}
akshitmohan said:int a,b,i;
cout<<"Enter the number whose factorial is to be calculated -";
for(i=a; i>=1; i--)
{
b=a*i;
But doesn't work ...
What in the world does that line do ^^ ?\/endett/\ said:#include <iostream.h>
#include <conio.h>
void main ()
{
int a,b=1;
cout<<"Enter the number whose factorial is to be calculated -";
cin>>a;
for(a;a>1;a--) {
b*=a;
}
cout<<endl<<b;
getch();
}
This works on BC++ 4.5
for(a;a>1;a--)
#include<stdio.h>
int fact(int i)
{
if(i==1)
return 1;
else
return (i*fact(i-1));
}
int main()
{
printf("%d",fact(1));
printf("%d",fact(5));
return 1;
}