Write a program that asks the user to enter three different integers; if the entered three integers contain two or more that are the same, print message "wrong input"; otherwise the program prints the largest number in the three. Implement your code using decision structures (namely, if and/or if-else).
In the execution of your code, try the following test cases.
Test case 1: input (3, 4, 5)
Test case 2: input (3, 3, 5)
Test case 3: input (3, 5, 3)
Test case 4: input (5, 3, 3)
Test case 5: input (-20, -40, -30)
Required Code C -
#include <stdio.h>
int main()
{
int a,b,c; // we declare three variables a,b,c
printf("Enter first number");
scanf("%d",&a); //enter 1st number
printf("Enter second number");
scanf("%d",&b); //enter 2nd number
printf("Enter third number");
scanf("%d",&c); //enter 1st number
if(a==b||a==c||b==c){ // if any of the two numbers is same
printf("Wrong Input"); // output is - wrong input
}
else{
if(a>b){
if(a>c){
printf("%d",a); // if a is greater then, a is printed
}
else{
printf("%d",c); //else c is printed
}
}
else if(b>a){
if(b>c){
printf("%d",b); // if b is greater then, output is b
}
else{
printf("%d",c); // else output is c
}
}
else{
printf("%d",c); // else output is c
}
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.