Function not working in c

c, function

Solution

None of your function should work. The first one set in the variable `a` the current value of `sum`which is unitialized.

Then when searching for the MAX value, you check if current sum (supposed to be `a`) is greater than `b` and if it is you store `b` value in `sum`.

Then if you want to call a function before it is defined you need to put the prototype of the function at the beginning of your file. As you are calling `min()` and `max()` before their definition you are having 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);
}

Problem

I am learning C programming and wrote a simple program to learn function in C. I have used two functios here, although the first one works but not the second one ! Here is the 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 anyone tell me why this happens and the solution?

Original source