大神幫我看看代碼
#include <stdio.h>
void printscore(int score[n])
{
? ? int i;
? ? printf("\n");
? ? for(i=0;i<n;i++)
? ? ? ? {
? ? ? ? ? ? printf("%d",score[i]);
? ? ? ? }
? ? printf("\n");
}
int gettotalscore(int score[n])
{
? ? int sum=0;
? ? int i;
? ? for(i=0;i<n;i++)
? ? {
? ? ? ? sum+=score[i];
? ? }
? ? return sum;
}
int main()
{
? ? int score[n]={67,98,75,63,82,79,81,91,66,84};
? ? int sum;
? ? printf("總分是:%d",sum);
? ? return 0;
}
運行錯誤;還有void那一段能省略么?它為什么存在?
2018-03-06
我的理解是:
首先你的n并沒有聲明和初始化;
sum=gettotalscore(score[]);
當你以數組作為參數時,是把數組名傳入,即sum=gettotalscore(score);
void那段可以省略,它的作用是將數組遍歷輸出,你如果在main函數中調用,那么就會將arr[]輸出;
如若存在錯誤或不足,請多指教
2018-01-31
大哥,你的代碼我也看了 ?我試了 能運行成功。我按照自己的想法試著修改,依舊失敗。我真的很笨,你就直接告訴我問題出在哪里,定義函數,引入函數哪里錯了。我后來主函數里 加了 ? sum=gettotalscore(score[]);
2018-01-30
#include <stdio.h>
void printscore(int score[],int n)
{
? ? int i;
? ? printf("\n");
? ? for(i=0;i<n;i++)
? ? ? ? {
? ? ? ? ? ? printf("%d\t",score[i]);
? ? ? ? }
? ? printf("\n");
}
int gettotalscore(int score[],int n)
{
? ? int sum=0;
? ? int i;
? ? for(i=0;i<n;i++)
? ? {
? ? ? ? sum+=score[i];
? ? }
? ? return sum;
}
int main()
{
? ? int score[]={67,98,75,63,82,79,81,91,66,84};
? ??
printscore( score, 10);
?printf("總分是:%d",gettotalscore( score, 10));
? ? return 0;
}
/*這是我自己改完的,void開頭的函數是顯示分數,,,,,,,,,,,,,,代碼粘貼上就可以看結果;
給個積分。。。。。,*/