标题:求解决WHILE 与FOR转换的问题(关于计算M名学生N门课程个人平均成绩)
只看楼主
教皇
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2011-10-6
结帖率:95.65%
已结贴  问题点数:10 回复次数:1 
求解决WHILE 与FOR转换的问题(关于计算M名学生N门课程个人平均成绩)
用FOR语句
#include <stdio.h>
main ()
{int m,n,i,j;
float v,s,x;
printf("press the number of students and the number of the courses\n");
scanf("%d,%d",&m,&n);
i=1;
for(;i<=m;i=i+1)

{printf("%d",i);
    for(s=0,j=1;j<=n;j++ )
{
    scanf("%f",&x);
s=s+x;
}
v=s/n;
printf("%f\n",v);
}
}

用WHILE语句
#include <stdio.h>
main ()
{int m,n,i,j;
float v,s,x;
printf("press the number of students and the number of the courses\n");
scanf("%d,%d",&m,&n);
i=1;
while (i<=m)
{
printf("the %d student\n",i);
s=0;
j=1;
while (j<=n)
{
printf("press the %d course's score=\n",j);
scanf("%f",&x);
s=s+x;
j=j+1;
}
v=s/n;
printf("%f\n",v);
i=i+1;
}
}

用FOR语句怎么使和用WHILE语句一样在应用程序中出现提示语句如(请输入第K名成绩)
搜索更多相关主题的帖子: 课程 include number press 
2011-10-20 17:01
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
得分:10 
程序代码:
#include <stdio.h>
int main ()
{
    int m,n,i,j;
    float v,s,x;
    printf("press the number of students and the number of the courses\n");
    scanf("%d,%d",&m,&n);
    i=1;
    for(;i<=m;i=i+1)   
    {
        printf("the %d student\n",i);
        for(s=0,j=1;j<=n;j++ )
        {
            printf("press the %d course's score=\n",j);
            scanf("%f",&x);
            s=s+x;
        }
        v=s/n;
        printf("%f\n",v);
    }
    return 0;
}
2011-10-21 12:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-353023-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.175187 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved