Friday, September 2, 2016

// // Leave a Comment

Larger And Smaller Value C Program

Question: Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Use only the single-selection form of the if statement you learned in this chapter. The screen dialogue should appear as follows:
Larger smaller value test

/* 
 * Author: AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com 
 *
 * Program that calculate the circumference and area of a circle.
 */

#include <stdio.h>
int main ( ){
    int num1, num2, num3, sum, ave, prod, min, max;
    printf("Enter three numbers: ");
    scanf("%d%d%d", &num1, &num2, &num3);
    sum = num1 + num2 + num3;
    ave = (num1 + num2 + num3) / 3;
    prod = num1 * num2 * num3;
    printf("Sum is %d\n", sum);
    printf("Average is %d\n", ave);
    printf("Product is %d\n", prod);
    
    // 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;
}
Program output
Program output
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.