Friday, September 2, 2016

// // Leave a Comment

C Program To Compare Two Integer Numbers

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.
/* 
 * Author: AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com 
 *
 * Program that compares the values of two numbers.
 */

#include <stdio.h>
int main (void){
    int num1, num2;
    printf("Enter two integer numbers: ");
    scanf("%d%d", &num1, &num2);
    if (num1 > num2)
    printf("\n%d is larger.\n", num1);
    if (num2 > num1)
    printf("\n%d is larger.\n", num2);
    if (num1 == num2)
    printf("\nThese numbers are equal.\n");
    return 0;
}
Program output (equal)

Program output (larger)
Click here to see other solutions to Deitel C How To Program exercises.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately.

Thanks.