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

Set 40:

A one-way linked list with head nodes has been established in the given program, and each node in the linked list is linked in order according to the data in the node data field. The function of fun is to put the value of formal parameter x into a new node and insert it into the linked list. After insertion, the value of each node's data field still keeps increasing in order.
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> 
#include <stdlib.h> 
#define N 8 
typedef struct list 
{ int data; 
struct list *next; 
void fun( SLIST *h, int x) 
{ SLIST *p, *q, *s; 
s=(SLIST *)malloc(sizeof(SLIST)); 
while(p!=NULL && x>p->data) { 
SLIST *creatlist(int *a) 
{ SLIST *h,*p,*q; int i; 
h=p=(SLIST *)malloc(sizeof(SLIST)); 
for(i=0; i<N; i++) 
{ q=(SLIST *)malloc(sizeof(SLIST)); 
q->data=a[i]; p->next=q; p=q; 
return h; 
void outlist(SLIST *h) 
{ SLIST *p; 
if (p==NULL) printf("\nThe list is NULL!\n"); 
{ printf("\nHead"); 
do { printf("->%d",p->data); p=p->next; } while(p!=NULL); 
{ SLIST *head; int x; 
int a[N]={11,12,15,18,19,22,25,29}; 
printf("\nThe list before inserting:\n"); outlist(head); 
printf("\nEnter a number : "); scanf("%d",&x); 
printf("\nThe list after inserting:\n"); outlist(head); 

Problem solving ideas:
This problem requires that a number be inserted into an orderly linked list, and the nodes are still orderly after insertion. There are three in the program, which should be filled with appropriate contents to make the program run with correct results.
The first pointer of the data structure is required to be filled in the integer of the data structure, and the first pointer of the data structure is required to be filled in. According to the requirements of this question, insert an integer number into a linked list. This number has been passed in through the formal parameter X of the fun ction, so x should be filled in.
Second: use a while loop to find the position where a number is to be inserted. In the loop body, q actually retains the temporary variable of the position of the current linked list P. if x > p - > data, move the linked list pointer to the next result, and then judge whether it meets the conditions. If it is still greater than, q still retains the position of the linked list P. Therefore, P should be filled here.
The third place: after finding the node location, insert this number to complete the insertion process. Since the structure pointer s is allocated in the function body, and the next pointer of s already points to p, the next pointer of the current position q should point to the pointer s to complete the link of the linked list. Therefore, s should be filled here.

Given program modi1 The function of function fun in C is to calculate the product of numbers on each bit of positive integer num.
For example, if input: 252, the output should be: 20. If input: 202, the output should be: 0.
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 (long num) 

long k; 
{ k*=num%10 ; 
num\=10 ; 
} while(num) ; 
return (k) ; 
main( ) 
{ long n ; 
printf("\Please enter a number:") ; scanf("%ld",&n) ; 
printf("\n%ld\n",fun(n)) ; 

Problem solving ideas:
First: since there is no initial value assigned when k is defined, K is a random number. According to the requirements of the test question, K should be assigned as 1.
Second: the sign of division is /.

Please write a function fun. Its function is to calculate the average score of n courses and return the calculation result as the function value.
For example, if the scores of five courses are 90.5, 72, 80, 61.5 and 55, the value of the function is 71.80.
Note: some source programs have the file prog1 In C.
Do not change anything in the main function and other functions, and only fill in the curly brackets of function fun
Several statements you wrote.
Given source program:

#include <stdio.h> 
float fun ( float *a , int n ) 
{ float score[30]={90.5, 72, 80, 61.5, 55}, aver; 
aver = fun( score, 5 ); 
printf( "\nAverage score is: %5.2f\n", aver); 
NONO ( ); 

Problem solving ideas:
This problem uses a loop to calculate the average value, and the result is returned by the function value.
Reference answer:

float fun ( float *a , int n ) 
int i; 
float ave=0.0; 
for(i=0; i<n; i++) ave=ave+a[i] ; 
return ave; 

Added by legohead6 on Fri, 04 Mar 2022 00:49:20 +0200