Question: Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.
1 2 |
/* <br /> * Author: AGHATISE OSAZUWA<br /> * Website: www.cscprogrammingtutorials.com <br /> *<br /> * Program that compares the values of two numbers.<br /> */<br /><br />#include <stdio.h><br />int main (void){<br /> int num1, num2;<br /> printf("Enter two integer numbers: ");<br /> scanf("%d%d", &num1, &num2);<br /> if (num1 > num2)<br /> printf("n%d is larger.n", num1);<br /> if (num2 > num1)<br /> printf("n%d is larger.n", num2);<br /> if (num1 == num2)<br /> printf("nThese numbers are equal.n");<br /> return 0;<br />}<br /> |
Program output (equal) |
Program output (larger) |
Click here to see other solutions to Deitel C How To Program exercises.