填空题
请补充函数proc(),该函数的功能是判断一个数是否为回文数。当字符串是回文数时,函数返回字符串:yes!,否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如,abcdcba。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<string.h>
#include<stdio.h>
char *proc(char*str)
char *str1, *str2;
int i, t=0;
str1=str; str2=str+str1en(str)-1;
for(i=0; (1) ; i++)
if( (2) )
t=1;
break;
if( (3) )
return("yes!");
else
return("no!");
void main()
char str[50];
printf("Input: ");
scanf("%s", str);
printf("%s\n", proc(str));
【参考答案】
*str1++! =*str2--
热门
试题
问答题
下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为: a=0 1 2 3 4 5 9 7 4 5 4 3 8 3 6 3 5 6 8 7 2 1 0 9 8 则返回主程序后,S的值为3.750000。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容。 试题程序: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define M 5 double proc(int w[][M]) void main() int a[M][M]=0, 1, 2, 3, 4, 5, 9, 7, 4, 5, 4, 3, 8, 3, 6, 3, 5, 6, 8, 7, 2, 1, 0, 9, 8; int i, j; double s; system( CLS ); printf( *****The array***** n ); for(i=0; i<M; i++) for(j=0; j<M; j++) printf( %4d , a[i][j]); printf( n ); s=proc(a); printf( *****THE RESULT***** n ); printf( The sum is: %lf n , s);