填空题
从键盘输入一组小写字母,并保存在字符数组str中。请补充函数fun(),该函数的功能是:把字符数组str中ASCII码为奇数的小写字母转换成对应的大写字母,结果仍保存在原数组中。
例如,输入“abcdefg”,输出“AbCdEfG”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
void fun(char s[])
{
int i;
for( 【1】 ; 【2】 ;i++)
{
if( 【3】 )
s[i]-=32;
}
}
main()
{
char str[N];
clrscr();
printf("\n lnput a string:\n");
gets(str);
printf("\n*** original string ***\n");
puts (str);
fun (str);
printf("\n*** new string ***\n");
puts (str);
}
【参考答案】
[1]i=0
热门
试题
问答题
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构件数组s中,请编写函数fun(),它的功能是:把分数最高的学生数据放在h所指的数组中。注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:#include <stdio.h>#define N 16typedef struct{ char num[10];int s;}STREC;int fun(STREC *a,STREC *b){}main (){STREC s [N] = { { GA005 , 85 }, { GA003 , 76 },{ GA002 , 69 }, { GA004 , 85 }, { GA001 , 91 },{ GA007 , 72}, { GA008 , 64}, { GA006 , 87},{ GA015 , 85), ( GA013 , 91 }, { GA012 , 64 },{ GA014 , 91 ), { GA011 , 66}, { GA017 , 64 },{ GA018 , 64 }, { GA016 , 72 } };STREC h[N];int i, n;FILE *out;n=fun(s,h);printf( The %d highest score : n ,n);for (i=0; i<n; i++)printf( %s %4d n ,h[i].num, h[i].s); *输出最高分学生的学号和成绩* printf( n );out=fopen( out45.dat , w );fprintf(out, %d n ,n);for(i=0; i<n; i++)fprintf(out, %4d n ,h[i].s);fclose(out);}