Code:#include<stdio.h> void main() { int a,b,c,sum; printf("\nEnter three num "); scanf("%d%d%d",&a,&b,&c); sum=calsum(a,b,c); printf("\nsum=%d",sum); } calsum(x,y,z) int x,y,z; { int d; d=x+y+z; return(d); }
error on compiling on tc++
Code:#include<stdio.h> void main() { int a,b,c,sum; printf("\nEnter three num "); scanf("%d%d%d",&a,&b,&c); sum=calsum(a,b,c); printf("\nsum=%d",sum); } calsum(x,y,z) int x,y,z; { int d; d=x+y+z; return(d); }
error on compiling on tc++
You can define a function before "main()".
You can also define a function after "main()", but it must be declared before "main()" with a prototype.
Code:// Method 1 - define a function before main #include <stdio.h> int sum(int a, int b) { return a + b; } int main(void) { int result; result = sum(2,3); return 0; }The return type, function name, and function arguments in the function definition should match those of the function prototype.Code:// Method 2 - define a function after main #include <stdio.h> int sum(int a, int b); // function declaration, or prototype (note semicolon) int main(void) { int result; result = sum(2,3); return 0; } int sum(int a, int b) // function definition (note no semicolon) { return a + b; }
thank you