C Program To Find Biggest of Three Numbers using Function


In this video tutorial you’ll learn how to find biggest of three integer numbers using function.

Related Read:
Nested if else Statement In C
Biggest of 3 Numbers: C
Biggest of 3 Numbers Using Ternary Operator: C

Video Tutorial: C Program To Find Biggest of Three Numbers using Function



YouTube Link: https://www.youtube.com/watch?v=0fxG98WizAo [Watch the Video In Full Screen.]

Source Code: C Program To Find Biggest of Three Numbers using Function

  1. #include<stdio.h>  
  2.   
  3. int biggest(intintint); // function prototype  
  4.   
  5. int main()  
  6. {  
  7.     int a, b, c;  
  8.   
  9.     printf("Enter 3 integer numbers\n");  
  10.     scanf("%d%d%d", &a, &b, &c);  
  11.   
  12.     //function call biggest(a, b, c)  
  13.     printf("Biggest of %d, %d and %d is %d\n", a, b, c, biggest(a, b, c));  
  14.   
  15.     return 0;  
  16. }  
  17.   
  18. // function definition  
  19. int biggest(int x, int y, int z)  
  20. {  
  21.     if(x > y && x > z)  
  22.     {  
  23.        return x;  
  24.     }  
  25.     else  
  26.     {  
  27.        if(y > z)  
  28.           return y;  
  29.        else  
  30.           return z;  
  31.     }  
  32. }  

Output
Enter 3 integer numbers
50
40
60
Biggest of 50, 40 and 60 is 60

Source Code: C Program To Find Biggest of Three Numbers using Function, Using Ternary Operator

  1. #include<stdio.h>  
  2.   
  3. int biggest(intintint); // function prototype  
  4.   
  5. int main()  
  6. {  
  7.     int a, b, c;  
  8.   
  9.     printf("Enter 3 integer numbers\n");  
  10.     scanf("%d%d%d", &a, &b, &c);  
  11.   
  12.     //function call biggest(a, b, c)  
  13.     printf("Biggest of %d, %d and %d is %d\n", a, b, c, biggest(a, b, c));  
  14.   
  15.     return 0;  
  16. }  
  17.   
  18. // function definition  
  19. int biggest(int x, int y, int z)  
  20. {  
  21.    return( (x>y && x>z)?x:(y>z)?y:z );  
  22. }  

Logic To Find Biggest of 3 Numbers using Function

We ask the user to enter 3 integer numbers. We pass those 3 integer numbers to user defined function biggest. Inside function biggest we use ternary operator to determine the biggest of those 3 numbers. Function biggest returns the biggest of the 3 numbers back to the calling method/function – in above progam its main() method.

Note: Function biggest returns integer type data. And it takes 3 arguments of type integer. We’re calling function biggest from inside printf() function.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *