Skip to main content

Greatest of Four Number using Functions in C Programming

                        Hello everyone, this blog is to find the greatest of four numbers and we i am using the functions concept for this program. First we need a function named max_of_four(), and that accepts four number as parameter named a, b, c, d.
                            Our function is a combination of two greatest of two numbers, and it checks first two number and return the greatest then returns the greatest of next two numbers. This function is called form the main function and there  we get all inputs from the user.

Code:

# include <stdio.h>

int max_of_four(int a,int b,int c,int d)
{
    int max,max1;

    //max of a and b

    if(a>b)
    {
        max=a;
    }
    else {
    max=b;
    }

    //max of c and d

    if (c>d)
    {
        max1=c;
    }
    else {
    max1=d;
    }

    //greatest of four

    if (max > max1)
    
    {
        return max;
    }
    else {
    return max1;
    }
}

int main()
{
    
    int a,b,c,d,r;

    //getting input

    printf("Enter four numbers:");
    scanf("%d %d %d %d",&a,&b,&c,&d);

    //function call
    r=max_of_four(a,b,c,d);
    
    printf("Greatest of four number is %d",r);
}

Output:










Comments

Popular posts from this blog

Palindrome Checker Using Python

  Problem:               To find whether a given input is a palindrome or not. We use two methods to find the palindrome, one is using "reverse indexing" and "reverse function". Palindrome:  The term palindrome means, consider a string and reverse it then compare both the                                 string if they are equal then it is a palindrome. Code: def palindrome ( a ):     if a == a [::- 1 ]:         print ( "It is a Palindrome" )     else :         print ( "It is not a Palindrome" ) val = input ( "Enter the value" ) palindrome ( val )