Almost there

#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]
1. Where does main() function starts?
2. Where is block for the fact(int) function
3. also small(ish) typos
4. code tags

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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;
}


Read new comments. Hope this helps
Thanks :)
Topic archived. No new replies allowed.