C Program To Find Biggest of Two Numbers using Function


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

Related Read:
Biggest of Two Numbers: C
Biggest of Two Numbers Using Ternary Operator: C

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



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

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

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

Output 1
Enter 2 integer numbers
50
25
Biggest of 50 and 25 is 50

Output 2
Enter 2 integer numbers
-5
-10
Biggest of -5 and -10 is -5

Logic To Find Biggest of 2 Numbers using Function

We ask the user to enter 2 integer numbers. We pass those 2 integer numbers to user defined function biggest. Inside function biggest we use ternary operator to determine the biggest number. Function biggest returns the biggest of the 2 numbers.

x>y?x:y

Here if x is greater than y, x will be returned else y will be returned.

Note: Function biggest returns integer type data. And it takes 2 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 *