关于c语言的简单两道题 求大神帮忙秒杀 1,求1到10之间奇数的和与偶数的和 用循环结构完成
关于c语言的简单两道题求大神帮忙秒杀1,求1到10之间奇数的和与偶数的和用循环结构完成2,有5人3门课成绩编程求各科的平均分和总平均成绩谢谢...
关于c语言的简单两道题 求大神帮忙秒杀 1,求1到10之间奇数的和与偶数的和 用循环结构完成 2, 有5人3门课成绩 编程求各科的平均分和总平均成绩 谢谢
展开
2个回答
展开全部
1.
int oddSum = 0, evenSum = 0;
for(int i = 1; i <= 10; i++)
{
if(i %2 == 0 )
evenSum += i;
else
oddSum += i;
}
printf("奇数的和:%d, 偶数的和: %d\n", oddSum, evenSum);
2.
struct student {
float score1;
float score2;
float score3;
};
float sumScore1 = 0.0, sumScore2 = 0.0, sumScore3 = 0.0;
struct student students[5] = {0.0};
for(int i = 0; i < 5; i++)
{
scanf("%f %f %f", &students[i].score1, &students[i].score2, &students[i].score3);
}
for (int i = 0; i < 5; i++)
{
sumScore1 += students[i].score1;
sumScore2 += students[i].score2;
sumScore3 += students[i].score3;
}
printf("The average of the course1 is : %f\n", sumScore1/5);
printf("The average of the course2 is : %f\n", sumScore2/5);
printf("The average of the course3 is : %f\n", sumScore3/5);
printf("The total average score is : %f\n", (sumScore1 + sumScore2 + sumSore3)/15);
int oddSum = 0, evenSum = 0;
for(int i = 1; i <= 10; i++)
{
if(i %2 == 0 )
evenSum += i;
else
oddSum += i;
}
printf("奇数的和:%d, 偶数的和: %d\n", oddSum, evenSum);
2.
struct student {
float score1;
float score2;
float score3;
};
float sumScore1 = 0.0, sumScore2 = 0.0, sumScore3 = 0.0;
struct student students[5] = {0.0};
for(int i = 0; i < 5; i++)
{
scanf("%f %f %f", &students[i].score1, &students[i].score2, &students[i].score3);
}
for (int i = 0; i < 5; i++)
{
sumScore1 += students[i].score1;
sumScore2 += students[i].score2;
sumScore3 += students[i].score3;
}
printf("The average of the course1 is : %f\n", sumScore1/5);
printf("The average of the course2 is : %f\n", sumScore2/5);
printf("The average of the course3 is : %f\n", sumScore3/5);
printf("The total average score is : %f\n", (sumScore1 + sumScore2 + sumSore3)/15);
更多追问追答
追问
第二题呢
追答
第二题也回答了~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询