Write a program that reads three integer values (A, B, and C) from the keyboard and displays the larger of the three values, using

  1. if - else and a MAX help variable.
  2. if - else if - ... - else without help variable

  3. conditional operators and a MAX help variable

  4. conditional operators without any help variable


Difficulty level
Video recording
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
void main()
{
	int A, B, C;
 	int MAX;

 	printf("Please enter 3 integers :");
 	scanf("%d %d %d", &A, &B, &C);

 	if (A>B)
     		MAX=A;
 	else
     		MAX=B;
 	if (C>MAX)
     		MAX=C;
 	printf("The maximum= %d\n", MAX);
	getch();
}



#include<stdio.h>
#include<conio.h>
void main()
{
	int A, B, C;

 	printf("Please enter 3 integers :");
 	scanf("%d %d %d", &A, &B, &C);


 	printf("The maximum= ");

 	if (A>B && A>C)
     		printf("%d\n",A);
 	else if (B>C)
     		printf("%d\n",B);
 	else
     		printf("%d\n",C);
	getch();
}



#include<stdio.h>
#include<conio.h>
void main()
{
	int A, B, C;
	int MAX;

 	printf("Please enter 3 integers :");
 	scanf("%d %d %d", &A, &B, &C);

 	MAX = (A>B) ? A : B;
 	MAX = (MAX>C) ? MAX : C;
 	printf("The maximum= %d\n", MAX);
	getch();
}



#include<stdio.h>
#include<conio.h>
void main()
{
	int A, B, C;

 	printf("Please enter 3 integers :");
 	scanf("%d %d %d", &A, &B, &C);

	printf("The maximum=  %i\n", 
                         (A>((B>C)?B:C)) ? A : ((B>C)?B:C));

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Compare 2 strings without using strcmp