Function not working in c

I study programming in C and wrote a simple program to learn functions in C. I used two functions here, although the first works, but not the second!

Here is a simple code:

#include<stdio.h> void main() { int a,b,c,sum; printf("Input your numbers one by one:\n"); scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); printf("You have put %d, %d, %d\n\n", a, b, c); max (a,b,c); min (a,b,c); } void max (int a, int b, int c) { int sum; a=sum; if(sum>b) sum=b; if(sum>c) sum=c; } void min (int f, int g, int h) { int sum; sum=f; if(sum<g) sum=g; if(sum<h) sum=h; printf("The lowest value is:%d\n\n\n",sum); } 

Can someone tell me why this is happening and the decision?

+4
source share
1 answer

None of your features should work. The first of them sets the current value sum to variable a , which is unified.

Then, when looking for the MAX value, you check if the current amount (presumably a ) is greater than b , and if you store the value of b in sum .

Then, if you want to call a function before defining it, you need to put a function prototype at the beginning of your file. Since you call min() and max() before defining them, you have compilation errors.

It should be like this:

 #include<stdio.h> void max (int a, int b, int c); void min (int f, int g, int h); void main() { int a,b,c,sum; printf("Put your numbers throughly one by one:\n"); scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); printf("You have putted %d, %d, %d\n\n", a, b, c); max (a,b,c); min (a,b,c); } void max (int a, int b, int c) { int sum; sum = a; if(sum<b) sum=b; if(sum<c) sum=c; printf("The max value is:%d\n\n\n",sum); } void min (int f, int g, int h) { int sum; sum=f; if(sum>g) sum=g; if(sum>h) sum=h; printf("The min value is:%d\n\n\n",sum); } 
+4
source

All Articles