Set 55:

In a given program, the function of the function fun is to judge whether the string referred to by the formal parameter s is a palindrome. If so, the return value of the function is 1; No, the return value of the function is 0. "Palindrome" is a string with the same forward and reverse reading (case insensitive).

For example, level and level are palindromes, while LEVLEV is not palindromes.

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 <string.h> #include <ctype.h> int fun(char *s) { char *lp,*rp; lp= __1__ ; rp=s+strlen(s)-1; while((toupper(*lp)==toupper(*rp)) && (lp<rp) ) { lp++; rp __2__ ; } if(lp<rp) __3__ ; else return 1; } main() { char s[81]; printf("Enter a string: "); scanf("%s",s); if(fun(s)) printf("\n\"%s\" is a Palindrome.\n\n",s); else printf("\n\"%s\" isn't a Palindrome.\n\n",s); }

Problem solving ideas:

This question is to judge whether the string is a palindrome.

First: according to the use of the variable lp in the function body fun, lp should point to the formal parameter s, so: s should be filled in.

The second place: rp is the pointer to the end of the string. When you make a loop, rp points to the previous character, so you should fill in: –.

The third place: when lp and rp are equal, it means that the string is a palindrome and returns 1. Otherwise, it returns 0, so you should fill in: return 0.

Given program modi1 The function of fun function in C is to find the sum of the first n terms of the following fractional sequence.

2 3 5 8 13 21 ┄, ┄, ┄, ┄, ┄, ┄, ┄, ┄, ┄,... 1 2 3 5 8 13 and the value return to the main function through the function value.

For example, if n = 5, it should output: 8.391667.

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> fun (int n ) { int a = 2, b = 1, c, k ; double s=0.0 ; for ( k = 1; k <= n; k++ ) { s = s + 1.0 * a / b ; c = a; a += b; b += c; } return(s) ; } main( ) { int n = 5 ; printf( "\nThe value of function is: %lf\n", fun ( n ) ) ; }

Problem solving ideas:

First: since the calculated real value must be returned through the function, the return type of the function must be defined. As long as int or void can be omitted, other types must be defined. Since the return is a real value, you should add a definition such as double or float before the number name.

Second: according to the formula, the value of b in the for loop should be c.

Please write the function fun. The function is to store k prime numbers greater than the formal parameter m and close to m into the array indicated by xx. For example, if you input 17, 5, you should output: 19, 23, 29, 31, 37. The statements given in the function fun are for reference only.

Note: some source programs are in the file prog1 C file.

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> void fun(int m, int k, int xx[]) { int i, j=1, t=m+1; while(j<=k) { /* The following completes the judgment of prime numbers and stores them in the array xx */ } } main() { int m, n, zz[1000] ; printf( "\nPlease enter two integers:") ; scanf("%d%d", &m, &n ) ; fun( m, n, zz) ; for( m = 0 ; m < n ; m++ ) printf("%d ", zz[m]) ; printf("\n") ; NONO( ) ; }

Problem solving ideas:

This question is to examine how candidates judge that a number is a prime number, and then judge whether the obtained prime number meets the requirements of the meaning of the question. If so, it will be saved in the specified array xx, and finally returned by the formal parameter xx. This question is to use the while loop statement to find five prime numbers that meet the meaning of the question. Where, j is the control variable, m is the number of primes to be greater than and close to, k is the number of primes to be sought, and j is the number of primes currently sought. The for loop statement in the while loop body is to judge whether t is a prime number.

Reference answer:

void fun(int m, int k, int xx[]) { int i, j=1, t=m+1; while(j<=k) { /* The following completes the judgment of prime numbers and stores them in the array xx */ for(i = 2 ; i < t; i++) if(t % i==0) break; if(i==t) { xx[j-1] = i; j++; } t++; } } }