# 100 sets of grade II C operation questions in the national computer grade examination question bank (set 08)

Posted by Chrysanthus on Sat, 05 Mar 2022 04:08:15 +0100

Set 08:
The given program uses structural variables to store a student's student number, name and grades of three courses by defining and assigning initial values. The function of fun is to multiply the student's grades in all subjects by a coefficient a. Please fill in the correct content in the underline of the program and delete the underline to make the program get the correct result.
Note: the source program is stored in blank1 under the examinee folder In C.
Do not add or delete lines, nor change the structure of the program!
Given source program:

```#include <stdio.h>
typedef struct
{ int num;
char name;
float score;
}STU;
void show(STU tt)
{ int i;
printf("%d %s : ",tt.num,tt.name);
for(i=0; i<3; i++)
printf("%5.1f",tt.score[i]);
printf("\n");
}
void modify(___1___ *ss,float a)
{ int i;
for(i=0; i<3; i++)
ss->___2___ *=a;
}
main( )
{ STU std={ 1,"Zhanghua",76.5,78.0,82.0 };
float a;
printf("\nThe original number and name and scores :\n");
show(std);
printf("\nInput a number : "); scanf("%f",&a);
modify(___3___,a);
printf("\nA result of modifying :\n");
show(std);
}
```

Problem solving ideas:
This problem is to use the structure to store student records and return them by the argument ss.
First: the argument ss is a structural pointer variable, so it should be filled in: STU.
Second: the student's grades in all subjects are multiplied by a coefficient a, so it should be filled in: score[i].
The third place: function call. Since the pointer structured variable is used in function definition, it should be filled in: & STD.

Given program modi1 The function of function fun in C is: find K! (k < 13), the value of the factorial is returned as the function value. For example: if k = 10, it should output: 3628800.
Please correct the mistakes in the program so that it can get the correct results.
Note: do not change the main function, do not add or delete lines, and do not change the structure of the program!
Given source program:

```#include <stdio.h>
long fun ( int k)
{
if k > 0
return (k*fun(k-1));

else if ( k=0 )
return 1L;
}
main()
{ int k = 10 ;
printf("%d!=%ld\n", k, fun ( k )) ;
}
```

Problem solving ideas:
First place: lack of parentheses in condition judgment.
The second place: the symbol for judging equality is = =.

The program defines n × N, and automatically assign values in the main function. Please write the function fun(int a[][N], int n). The function is to multiply the value in the lower left triangular element of the array by n.
For example, if the value of n is 3, the value in the array of a is | 1 9 7 | 3 9 7|
a = | 2 3 8 | then the value in the a array after returning the main program should be | 6 9 8|
| 4 5 6 | | 12 15 18|
Note: some source programs have the file prog1 In C.
Do not change anything in the main function and other functions. Only fill in the curly brackets of the function fun with some statements you have written.
Given source program:

```#include <stdio.h>
#include <stdlib.h>
#define N 5
int fun ( int a[][N], int n )
{
}
main ( )
{ int a[N][N], n, i, j;
printf("***** The array *****\n");
for ( i =0; i<N; i++ )
{ for ( j =0; j<N; j++ )
{ a[i][j] = rand()%10; printf( "%4d", a[i][j] ); }
printf("\n");
}
do n = rand()%10 ; while ( n >=3 );
printf("n = %4d\n",n);
fun ( a, n );
printf ("***** THE RESULT *****\n");
for ( i =0; i<N; i++ )
{ for ( j =0; j<N; j++ ) printf( "%4d", a[i][j] );
printf("\n");
}
NONO( );
}
Problem solving ideas:
This problem is to use a double loop to multiply the value in the lower left triangular element of a two-dimensional array n.