this is my question: Σ sum of terms from i=2 to 10, the equation is (n+2)/n!. I am using recursion for the sum and fact functions. Code: #include <stdio.h> #include <conio.h> int sum(int); long int fact(int); int main() { int n; long int s; clrscr(); printf("Enter Number:"); scanf("%d\n"&n); s=sum(n); printf("Sum of %d is =%d"n,s); getch(); } int fact(int i) { if (i<=0) return 1; else return (i*fact(i-1)); } int sum(int c) { if(c<2) return 0; if else (c>10) return 0; else return ((c+2)/fact©); } I am getting the following error: Illegal use of pointer in the line "scanf("%d\n"&n);" at n what did i do wrong?
If it's not a typo, the printfs and scanfs are missing commas. having "%d\n" in scanf is kinda hokie too. Code: scanf("%d\n"&n); scanf("%d\n", &n); the fact function's return type is mismatched in the proto and definition. if this is some sort of convergence thing, integer division will probably return 0 before you'd want it to. maybe cast that printf sum result as a float or double??
I agree to the post of hobbyist, and also just to make everything clear and safe do the following instead: PHP: scanf("%d",&n); printf("\n"); Due to some reason, if we are using the '\n' inside scanf function, things gets complicated and sometimes gives errors such as the one that you have encountered.
hai, Why do we need a '\n' for scanf??? when u are enter a number, character or string at the end we will press enter which give us a newline character so i think there is no point in giving '\n' in scanf. Regards SHIBIN K REEN