#include <stdio.h>
int fact(int x);// Declaring function
int num;
printf("Please Enter a number");
scanf("%d",&num);
if(num<0){
printf(" No negative numbers, please.\n");
}
else
}
if (num>15)
{
printf( "Too large\n");
}
else
{
printf ("%d fact = %d\n",num, fact(num));
}
}
}
int fact (int x)//Writing down function process
int = ans =1;
for (; x>1; x=x-1)
{
ans = ans *x;// working
}
return ans;
}
[ To do a factorial ] [ may i know where the errors :P]
#include <stdio.h>
int fact(int x);
int main() // main is here
{ // Start of main block
int num;
printf("Please Enter a number");
scanf("%d",&num);
if(num<0){
printf(" No negative numbers, please.\n");
}
else
{ // Was wrong way
if (num>15)
{
printf( "Too large\n");
}
else
{
printf ("%d fact = %d\n",num, fact(num));
}
}
return 0; // main done correctly -> exit
} // end of main block
int fact (int x)
{ // start of fact() block
// int = ans =1;
int ans = 1;
for (; x>1; x=x-1)
{
ans = ans *x;
}
return ans;
}