Home > Back-end >  Small white one, c language programming problem, I ask you a great god
Small white one, c language programming problem, I ask you a great god

Time:01-06

Subject content: write a program that includes the main function and the fun function: the function of the main function is to input from the user's m personal achievement in score in the array, call fun function, and output the highest score and highest in number; Function is the function of fun to find the highest score and highest in serial number, will be the highest in Max, the serial number in Num; Require the use of two global variables, the fun function prototype: void fun (int score [], int m) test case: when the score of the array data for 10,20,30,90,60,70,80, the main function output 90,

I write programs:
#include
Int Max;
Int Num.
Int main () {
Void fun (int score [], int m);
int n;
Int m=7;
Int score [7]={0};
for (int i=0; I & lt; 7. I++) {
scanf("%d", & N);
Score [I]=n;
}

Fun (score, m);//to find the maximum
Printf (" supreme divided into % d, the highest number of % d ", Max, Num);//output
return 0;
}
Void fun (int score [], int m) {
int j;
Int Max=score [0];
For (j=0; J & lt; m; J++) {
If (score [j] & gt; Max)
Max=score [j];
Num=j + 1;
}
} is not an error but the result not

CodePudding user response:

Come to a big help children

CodePudding user response:

You define int Max, in a fun, on the other hand, the global Max blocked, num in the if

 
Void fun (int score [], int m)
{
int j;
Max=score [0];

For (j=0; J & lt; m; J++)
{
If (score [j] & gt; Max)
{
Max=score [j];
Num=j + 1;
}
}
}

CodePudding user response:

refer to the second floor rogue response:
you define int Max, in a fun, on the other hand, the global Max blocked, num in the if

 
Void fun (int score [], int m)
{
int j;
Max=score [0];

For (j=0; J & lt; m; J++)
{
If (score [j] & gt; Max)
{
Max=score [j];
Num=j + 1;
}
}
}

(^??? Thank you ^) thank you
  • Related