Find maximum value among three integers using user defined function - C

Q. Write a program to find maximum value among three integers using user defined function.
 #BIT-C Programming-2019-GroupB-6No-4 Marks-Solution

==>Code goes like this:

#include<stdio.h>
int greater( int, int); //function declaration || prototyping
int main()
{
    int num1,num2,num3,d,e;
    printf("Enter three numbers:");
    scanf("%d %d %d",&num1,&num2,&num3); 
    d=greater(num1,num2);
    /* stores the greater number between first and second number to variable d */
    e=greater(d,num3);
    /* e stores the greater value between first, second and third num */
    printf("The greatest number is %d",e);
    return 0;
}
int greater(int x, int y) /* function definition */
{
    if(x>y)
    return (x);  /* returns first number to calling varialbe */
    else
    return(y);  //returns second number to calling variable */
}

Output:






If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment