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
Page Contents
#include<stdio.h> int biggest(int, int, int); // function prototype int main() { int a, b, c; printf("Enter 3 integer numbers\n"); scanf("%d%d%d", &a, &b, &c); //function call biggest(a, b, c) printf("Biggest of %d, %d and %d is %d\n", a, b, c, biggest(a, b, c)); return 0; } // function definition int biggest(int x, int y, int z) { if(x > y && x > z) { return x; } else { if(y > z) return y; else return z; } }
Output
Enter 3 integer numbers
50
40
60
Biggest of 50, 40 and 60 is 60
#include<stdio.h> int biggest(int, int, int); // function prototype int main() { int a, b, c; printf("Enter 3 integer numbers\n"); scanf("%d%d%d", &a, &b, &c); //function call biggest(a, b, c) printf("Biggest of %d, %d and %d is %d\n", a, b, c, biggest(a, b, c)); return 0; } // function definition int biggest(int x, int y, int z) { return( (x>y && x>z)?x:(y>z)?y:z ); }
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