Saturday, September 3, 2016

// // Leave a Comment

C Program To Determine Largest And Smallest Integers

Question: Write a program that reads in three integers and then determines and prints the largest and the smallest integers in the group. Use only the programming techniques you have learned in this chapter.
/* 
 * Author: AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com 
 *
 * Program to calculate and print Largest and Smallest Integers.
 */

#include <stdio.h>
int main ( ){
    //Program to print largest and smallest numbers.
    int num1, num2, num3, min, max;
    printf("Enter three integer numbers: ");
    scanf("%d%d%d", &num1, &num2, &num3);
    
    // Let's assume num1 is the minimum(smallest) number
    min = num1;   
    if (num2 < min){
    min = num2;
    }
    if (num3 < min){
    min = num3;
    }
    printf("Smallest is %d\n", min);
    
    // Let's assume num1 is the maximum(largest) number
    max = num1;   
    if (num2 > max){
    max = num2;
    }
    if (num3 > max){
    max = num3;
    }
    printf("Largest is %d\n", max);
    return 0;
}
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.