Experiment 2-1-4 Calculate the average score (5 points)

Knowing that the scores of a student in math, English and computer courses are 87, 72, and 93 respectively, find the average score of the student's 3 courses (the results are output as integers).

Input format:

No input for this question

Output format:

Output the results in the following format:

math = 87, eng = 72, comp = 93, average = 计算所得的平均成绩

Code:

# include <stdio.h>
# include <stdlib.h>

int main(){
    
    
    int math = 87,eng = 72,comp = 93,average;
    average = (math + eng + comp) / 3;
    printf("math = %d, eng = %d, comp = %d, average = %d",math,eng,comp,average);
    return 0;
}

Submit screenshot:

Insert picture description here

Problem-solving ideas:

Title relatively simple, nothing more than the creation and assignment variable, average note final output is an integer, so defined averagewhen the variables can be defined as the direct inttype, may of course be provided double, or float, when the symbol with the final output format %0lf, or%0f

Guess you like

Origin blog.csdn.net/weixin_43862765/article/details/114362954