Friday, September 19, 2014

// // Leave a Comment

Highest and Lowest Value Program

Program to accept five integer values from the user and calculate the sum, product, average, highest value and lowest value.

/* 
 * Author: AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com 
 * 
 *
 * Program to calculate the sum, product, average, highest value and
 * lowest value of 5 integer numbers. */

#include <stdio.h>

int main (void) {
    int a, b, c, d, e, sum, prod, ave;
    printf("%s", "Enter five integer numbers: ");
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    sum = a + b + c + d + e;
    printf("Sum is %d\n", sum);
    prod = a * b * c * d * e;
    printf("Product is %d\n", prod);
    ave = (a + b + c + d + e) / 5;
    printf("Average is %d\n\n", ave);
    
    /*calculate for highest number*/

    if (a > b && a > c && a > d && a > e){
          printf("Highest number is %d\n", a);
       }
    else if (b > a && b > c && b > d && b > e){
          printf("Highest number is %d\n", b);
       }
    else if (c > a && c > b && c > d && c > e){
          printf("Highest number is %d\n", c);
       }
    else if (d > a && d > b && d > c && d > e){
          printf("Highest number is %d\n", d);
       }
    else if (e > a && e > b && e > c && e > d){
          printf("Highest number is %d\n", e);
       }
    else {
         puts ("One or more numbers are equal.");
       }
  
    /*calculate for lowest number*/

    if (a < b && a < c && a < d && a < e){
          printf("Lowest number is %d\n", a);
       }
    else if (b < a && b < c && b < d && b < e){
          printf("Lowest number is %d\n", b);
       }
    else if (c < a && c < b && c < d && c < e){
          printf("Lowest number is %d\n", c);
       }
    else if (d < a && d < b && d < c && d < e){
          printf("Lowest number is %d\n", d);
       }
    else if (e < a && e < b && e < c && e < d){
          printf("Lowest number is %d\n", e);
       }
    else {
         puts ("One or more numbers are equal.");
       }  
   
    return 0;
} 


Below is the output:

Highest and Lowest value program

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.