為什么在VC上無法正常運行
#include <stdio.h>
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? float sum;
? ? int n;
? ? for(n=0;n<10;n++)
? ? {
? ? ? ? sum+=score[n];
? ? }
? ? float ave=sum/10;
? ? int i,j;
? ? int temp;
? ? for(i=1;i<10;i++)
? ? {
? ? ? ? for(j=8;j>=0;j--)
? ? ? ? {
? ? ? ? ? ? if(score[j+1]>score[j])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=score[j];
? ? ? ? ? ? ? ? score[j]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? printf("班級10個學生的考試成績總分為%.2f。\n",sum);
? ? printf("班級10個學生的考試成績最高分為%d。\n",score[0]);
? ? printf("班級10個學生的考試成績最低分為%d。\n",score[9]);
? ? printf("班級10個學生的考試成績平均分為%.2f。\n",ave);
? ? printf("班級10個學生的考試成績降序排序為:\n");
? ? int a;
? ? for(a=0;a<10;a++)
? ? {
? ? ? ? printf("%d ",score[a]);
? ? }
? ??
? ? return 0;
}
2019-03-03
?float sum;
這一步沒有賦初值
應該?float sum=0.0;
2019-03-02
記得吧VC的報錯一起貼出來,大部分人是沒耐心一行行檢查代碼的