Exercise 2-1 Find the mean value of an integer (10 points)
This question requires writing a program to calculate the sum and average of 4 integers. The question guarantees that the input and output are within the integer range.
Input format:
Input 4 integers in one line, separated by spaces.
Output format:
In a row, output the sum and average value in the order of the format "Sum = and; Average = average value", where the average value is accurate to one decimal place.
Input sample:
1 2 3 4
Output sample:
Sum = 10; Average = 2.5
Author
Qiao Lin
Unit
Tsinghua University
Code length limit
16 KB
Time limit
400 ms
Memory limit
64 MB
#include <stdio.h>
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("Sum = %d; Average = %.1f", a + b + c + d, (a + b + c + d) / 4.0);
return 0;
}