Hi
i want to make program for 3 input integer and show output by a maximum value in it by using function so anybody help me
reply me earlier

Can you do it all in main? If all you need to do is refactor, that is relatively easy. Take a simple adder for example:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;

    printf("2 numbers to add: ");

    if (scanf("%d%d", &a, &b) != 2)
    {
        fputs("Error reading expected numbers\n", stderr);
        return EXIT_FAILURE;
    }

    printf("%d + %d = %d\n", a, b, a + b);

    return 0;
}

a+b is a simple expression, but you might want to refactor it into a function. The first step is to decide how you want to use the function. In this case having it take a and b as arguments and return the result makes sense. Your maximum value function would probably work the same way. Next, cut out the expression and replace it with the function call you want:

/*
Not working code
*/
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;

    printf("2 numbers to add: ");

    if (scanf("%d%d", &a, &b) != 2)
    {
        fputs("Error reading expected numbers\n", stderr);
        return EXIT_FAILURE;
    }

    printf("%d + %d = %d\n", a, b, add(a, b));

    return 0;
}

Now it is just a matter of defining a function with the same interface and making the body of the function do what needs to be done. If you name the parameters the same as the arguments being passed in, you can paste the expression that you cut out earlier:

#include <stdio.h>
#include <stdlib.h>

int add(int a, int b)
{
    /* same expression but as a return statement */
    return a + b;
}

int main()
{
    int a, b;

    printf("2 numbers to add: ");

    if (scanf("%d%d", &a, &b) != 2)
    {
        fputs("Error reading expected numbers\n", stderr);
        return EXIT_FAILURE;
    }

    printf("%d + %d = %d\n", a, b, add(a, b));

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.