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 https://www.youtube.com/watch?v=PF7sGUN_U_M]

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

#include<stdio.h>

int biggest(int, int); //  function prototype

int main()
{
    int a, b;

    printf("Enter 2 integer numbers\n");
    scanf("%d%d", &a, &b);

    // function call biggest(a, b)
    printf("Biggest of %d and %d is %d\n", a, b, biggest(a, b));

    return 0;
}

//function definition
int biggest(int x, int y)
{
    return( x>y?x:y );
}

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 *