Experiment 2-2-5 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:

The input gives 4 integers on one line, separated by spaces.

Output format:

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

Sample input:

1 2 3 4
 

Sample output:

Sum = 10; Average = 2.5


#include<stdio.h>
int main ()
{
    int sum,a,b,c,d;
    double aver;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        sum=a+b+c+d;
    aver = 1.0 * I / 4;
    printf("Sum = %d; Average = %.1lf",sum,aver);
    return 0;
}

Guess you like

Origin www.cnblogs.com/wven/p/12682213.html