Question

Write a program that asks the user to enter three different integers; if the entered three...

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)

Homework Answers

Answer #1

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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user to input two integers. - If both of them are greater than zero, then output their sum. - If only one integer is greater than zero, then output their difference. - Otherwise, output a message "your two number <0".
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
Write a C program that asks the user to enter two integers x and n. Then...
Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. using printf scanf