Find the largest number of 3 number

Hello everyone, surely you know how to find the greatest among 2 numbers a and b. We only have to compare a to b, larger number, then take it alone. But with 3 of a, b, c then why?

Threads: Enter 3 integer a, b, c from the keyboard, Please print out the largest number of 3 which.

Simple way that you can think of is to compare a to b, then compare number to find the c. Very simple.

/*
* Find max of a, b, c
*/

#include <stdio.h>

int main() 
{
	int a, b, c;

	printf("Enter a, b and c\n");
	scanf("%d%d%d", &a, &b, &c);

	int max = a;
	if(max < b) 
	{
		max = b;
	}

	if(max < c) {
		max = c;
	}

	printf("Max is %d\n", max);

	return 0;
}

Very simple, right. However, if we upgraded bit is finding the largest number of 4 No. Then why? Similar making severance, but will need more 1 again to check if the. With 5 number, 6 number, every time we would need more 1 if. Somewhat lengthy. So you think, how user content nhé. We build 1 find the max function between 2 number, then we can use it very convenient. Like the example below.

Threads: Enter 4 number a, b, c, d from the keyboard, Look for the largest number of 3 of a,b, c and the largest number of 4 of a, b, c, d.
/*
* Find max of a, b, c, d
*/

#include <stdio.h>

int max(int x, int y) 
{
	if(x > y) return x;
	return y;
}

int main() 
{
	int a, b, c, d;

	printf("Enter a, b, c and d\n");
	scanf("%d%d%d%d", &a, &b, &c, &d);

	int max3 = max( max(a, b), c );
	printf("Max of a, b, c is %d\n", max3);

	int max4 = max( max(a, b), max(c, d) );
	printf("Max of a, b, c, d is %d\n", max4);

	return 0;
}

Very simple solution is not. Max function returns the maximum value of 2 number, then we can take it to compare with the other numbers.

In case of finding the largest number of lot number, then you go used to Plate to enter and store them, then find the largest number in the array.

Exercise: Enter sequence of n integers from the keyboard (n typing), Look for the largest number in the sequence n number entered.