请补充函数fun(),该函数的功能是:从‘a’到‘z’统计一个字符串中所有字母字符各自出现的次数,结果保存在数组aIf中。注意:不区分大小写,不能使用字符串库函数。
例如,输入: “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++)
【 】;
while(*p)
{
if(*p>='A'&&*p<='z')
【 】;
if(*p>='a'&&*p<='Z')
alf[*p-'a']++;
【 】;
}
}
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题
符串中,例如:把3个串DEG,ac,df反着串联起来,结果是dfacDEG。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或者删行,也不得改变程序的结构!
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
void fun(char str[][10],int m,char *pt)
{
int k,q,i,j=0;
/*************found*************/
for(k=m;k>0;k--)
{
q=strlen(str[k]);
j+=q;
for(i=0;i<q;i++)
pt[i]=str[k][i];
pt+=q;
pt[0]=0;
}
/*************found**************/
pt=j;
}
main()
{int m,h;
char s[10][10],p[120];
clrscr();
printf("\nPlease enter m:");
scanf("%d",& m);
printf("\nPlease enter%d string:\n",m);
gets(s[0]);
for(h=0;h<m;h++)
gets(s[h]);
fun(S,m,p);
printf("/nThe result iS:%s\n",p);
}
第2题
在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("\nPIease enter S:");
scanf(“%ld”,&s);
fun(S,&t);
printf(“The result is:%ld\n”,t);
}
第3题
执行以下程序的输出结果是( )。
include<stdio.h>
define M 5
define N M+M
main()
{ int k;
k=N*N*5;printf(”%d\n" ,k);
}
第4题
以下程序的作用是:从名为filea.dat的文本文件中逐个读入字符并显示在屏幕上。请填空。
include <stdio.h>
main()
{FILE *fp; char ch;
fp=fopen(【 】);
ch=fgetc(fp);
while(!feof(fp)) { putchar(ch); ch=fgetc(fp); }
putchar('\n');fclose(fp);
}
第5题
以下程序运行后的输出结果是( )。
main()
{ int x,a=1,b=2,c=3,d=4;
{ int x,a=1,b=2,c=3,d=4;
x=(a<B)?a:b;x=(a<C)?x:C;x=(d>x)?x:d;
printf("%d\n",x);
}
第6题
以下程序运行后的输出结果是( )。
include
char*ss(char*s)
{char*p,t;
P=s+1;t=*s;
while(*p){ *(P-1)=*P;P++;}
*(P-1)=t;
return s;
}
main()
{char*p,str[10]="abcdefgh";
p=ss(str);
printf("%s\n",p);
}
第7题
个素数通过形参指针传回主函数。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <math.h>
void fun(int a, int *b, int *c)
{ int i,j,d,y;
for (i=3;i<=a/2;i=i+2)
/*************found**************/
{y=0;
for (j=2;j<=sqrt((double)i);j++)
if (i%j==0) y=0;
if (y==1)
/*************found**************/
{ d=i-a;
for (j-2;j<=sqrt((double)d);
j++)
if (d%j==0) y=0;
if (y=-1)
{*b=i; *c=d;}
}
}
}
main ()
{ int a,b,c;
do
{ printf("\nInput a: ");
scanf ("%d", &a); }
while (a%2);
fun (a, &b, &c);
printf ("\n\n%d=%d+%d\n", a,b,c);
}
第8题
请补充函数fun,该函数的功能是比较字符串str1和str2的大小,井返回比较的结果。
例如: 当str1=“cdef",str2=“cde”时,函数fun()返回“>”。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include< stdio, h>
include<conio. h>
define N 80
char *fun (char *str1,char *str2)
{
char *p1=str1, *p2=str2;
while (*p1 & & *p2 )
{
if (【 】)
return "<";
if(【 】)
return ">";
p1++;
p2++;
}
if (*p1=*p2)
return "==";
if (*p1==【 】)
return "<";
else
return ">";
}
main()
{
char str1 [N], str2 [N];
clrscr ();
printf ("Input str1: \n");
gets (str1);
printf ("Input str2: \n");
gets (str2);
printf ("\n*****the result*****\n");
printf ("\nstr1 %s str2", fun (str1, str2) );
}
第9题
结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio. h>
include<conio. h>
include<stdlib. h>
typedef struct ss
{
int data;
struct ss *next;
} NODE;
void fun(int n,char*filename)
{
NODE *h,*p, *s;
FILE *pf;
int i;
h=p= (NODE *) malloc (sizeof (NODE));
h->data=0;
for (i=1; i {
s=(NODE *)malloc (sizeof (NODE));
s->data=【 】;
【 】;
p=【 】
}
p->next=NULL;
if ( (pf=fopen (filename, "w") ) ==NULL)
{
printf {"Can not open out9B.clat! ");
exit (0);
}
p=h;
fprintf (pf, "\n***THE LIST***\n");
print f ("\n***THE LIST***\n")
while (p)
{
fprintf (pf, "%3d", p->data)
printf ("%3d",p->data);
if (p->next ! =NULL)
{
fprintf (pf, "->");
printf ("->");
}
p=p->next;
}
fprintf (pf, "\n");
printf ("\n");
fclose (pf);
p=h;
while (p)
{
s=p;
p=p->next;
free (s);
}
}
main()
{
char * filename="out98. dat";
int n;
clrscr ();
printf (" \nInput n: ");
scanf ("%d", &n);
fun (n, filename);
}
第10题
以下程序可把输入的十进制数以十六进制数的形式输出。
请在横线上填上适当的内容并把横线删除,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序;
main ()
{
char b[17]={"0123456789ABCDEF"};
int c[64] ,d,i=0,base=16;
long n;
printf("Enter a number:\n");
scanf ("%ld", &n);
do {
/*****************found****************/
c[i]=______; i++; n=n/base; }
while (n!=0);
printf("Transmite new base:\n");
for(--i;i>=0;--i)
/***************found*******************/
{ d=c[i];printf("%c",b______);}
printf("\n");
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!