开发者

new to using classes in C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
# include <stdio.h>

int main(void) {

int numStudents;
int i = 0 ;
int sum;

printf("How many students are in your class? \n");
scanf("%d", &numStudents);

int grade[numStudents];


while ( i < numStudents ){
      scanf("%d", &grade[i]);
      printf("\n");
      i++;
      }

average(int grade[numStudents]);
printf("%d", &sum);     

}


int average(int x[y]){
    int sum;

  开发者_JAVA百科  for (a=0; a<=y ;a++){
    sum = sum + x[a];
    }

    sum = sum / y;
    return sum;
}

I am asking what is wrong with my code.


For starters, this

int average(int x[y]){           /* wrong */
int average(int x[], int y){     /* probably what you want */

And

average(int grade[numStudents]); /* totally wrong */
average(grade, numStudents);     /* might work */

There is an off-by-one errory in average that I'm not pointing out since it's homework. I urge other posters not to point it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜