Zhejiang University Edition "C Language Programming (3rd Edition)" Exercise 2-1

Exercise 2-1 Find the integer mean (10 points)

This question requires a program to calculate the sum and average of 4 integers. The problem is to ensure that the input and output are within the integer range.

Input format:
Enter 4 integers in one line, separated by spaces .

Output format:
Sum and average values ​​are output in the order of the format "Sum = and; Average = average value" in one line, and the average value is accurate to one decimal place .

Sample input:

1 2 3 4

Sample output:

Sum = 10; Average = 2.5

The exercises are done a little before.
Look at the code :

#include"stdio.h"
int main()
{
    int a,b,c,d,Sum = 0;
    float Average;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    Sum = a + b + c + d;
    Average = Sum / 4.0;
    printf("Sum = %d; Average = %0.1f",Sum,Average);
    return 0;
}
Published 25 original articles · won 3 · views 240

Guess you like

Origin blog.csdn.net/oxygen_ls/article/details/105376400