填空题
请补充函数fun(),该函数的功能是:从‘a’到‘z’统计一个字符串中所有字母字符各自出现的次数,结果保存在数组alf中。注意:不区分大小写,不能使用字符串库函数。
例如,输入:“A=abc+5*c”,结果为:a=2, b=l,c=2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数run的横线上填入所编写的若干表达式或语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define N 100
void fun(char *tt,int alf[])
int i
char *p=tt;
for(i=0;i<26;i++)
【1】
;
while(*p)
if(*p>=’A’&&*p<=’z’)
【2】
;
if(*p>=’a’&&*p<=’Z’)
alf[*p-’a’]++;
【3】
;
main()
char str[N];
char a=’a’;
int alf[26],k;
clrscr();
printf("\nPlease enter a char string:");
scanf("%s",str);
printf("\n**The original string**\n");
puts(str);
fun(str,alf);
printf("\n**The number of letter**\n");
for(k=0;k<26;k++)
if(k%5==0)
printf("\n");
printf("%c=%d",a+k,alf[k]);
printf("\n");
【参考答案】
[1] alf[i]=0 [2] *p+=32 [3] p++
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
填空题
下列给定程序中函数fun()的功能是;从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。例如,当s中的数为4576235时,t中的数为4725。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<stdio.h> #include<conio.h> ************found************* int fun(long s,long *t) long s1=l0; *tis%10; while(s>0) *************found************* s=s%100; *t=s%10*s1+*t; s1=s1*10; main() long s,t; clrscr(); printf( nPlease enter s: ); scanf( %ld ,&s); fun(s,&t); printf( The result is:%ld n ,t);
点击查看答案&解析
问答题
请编写一个函数fun(),它的功能是:求出一个4×M整型二维数组中最小元素的值,并将此值返回调用函数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仪在函数fun的花括号中填入所编写的若干语句。 试题程序: #define M 4 #include <stdio.h> fun (int a[])[M]) main() int arr[4][M]=11,3,9,35,42,-4,24,32,6,48,-32,7,23,34,12,-7); printf( min=%d n ,fun(arr));
点击查看答案&解析
相关试题
下列给定程序中函数fun()的功能是;从低...
请编写一个函数fun(),它的功能是:求出...