填空题下列给定程序中,函数fun的功能是:逐个比较p、q所指两个字符串对应位置上的字符,并把ASCII值大或相等的字符依次存放到c所指的数组中,形成一个新的字符串。
例如,若主函数中a字符串为“aBCDeFgH”,b字符串为“ABcd”,则C中的字符串应为“aBcdeFgH”。
请改正程序中的错误,使它能得出正确的结果。
注意
:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
void fun(char *p,char *q,char *c)
{
/********found********/
int k=1;
/********found********/
while(*p!=*q)
{if(*p<*q)c[k]=*q;
else c[k]=*p;
if(*p)p++;
if(*q)q++;
k++;
}
}
main()
{char a[10]="aBCDeFgH",b[10]="ABcd", c[80]={"/0"};
fun(a,b,c);
printf("The string a:");puts(a);
printf("The string b:");puts(b);
printf("The result:");puts(c);
}
填空题53. 以下程序运行后的输出结果是{{U}} {{/U}}。#include <stdio.h>#include <string.h>char * ss(char * s) char * p,t; p=s+1:t= *s: whilet * p) *(,p-1) = *p; p++; * (p-1) =t; return s : main ( ) char * p,str[10] =" abedefgh"; p = ss(str); printf( "% s //n". p):
填空题以下函数creat()用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾,结点数据域中的数值从键盘输入,以字符“?”作为输入结束标识。单向链表的头指针作为函数值返回。请填空。
试题程序 #include
<stdio.h> struct list { char data;
struct list *next }; struct list
*creat() struct list *h, *p, *q; char
ch; h=______ malloc(sizeof(______));
p=q=h; ch=getchar(); while(ch!='?')
{ p=______ mailoc(sizeof(______)); p->data=ch;
q->next=p; q=p; ch=getchar
(); } p->next='/0'; return
______; }
填空题有以下程序: main() int t=1, i=5; for(; i>=0; i--)t*=i; printf("% d//n", t); 执行后的输出结果是{{U}} {{/U}}。
填空题请补充main 函数,该函数的功能是:计算两个自然数n和m(m<10000)之间所有数的和(n和m从键盘输入)。 例如:当n=1,m=100时,sum=5050:当n=100,m=1000时,sum=495550。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #include<conio.h> main () int n, m; long sum; 【1】 clrscr (); printf ("/nInput n,m/n"); scanf ("%d, %d", while (n<=m) 【2】 n++; printf ("sum=% 【3】 /n", sum);
填空题若有以下程序 main() int a[4][4]=1,2,-3,-4,0,-12,-13,14,-21,23,0,-24,-21,32,-33,0; int i,j,s=0; for(i=0;i<4;i++) for(j=0;j<4;j++) if(a[i][j]<0)continue; if(a[i][j]==0)break; s+=a[i][j]; printf("%d/n",s); 执行后输出结果是 【10】 。
填空题由25人围坐成圆圈,先由任意一人开始顺时针沿用1~25依次编号,然后从1号开始顺时针报数(1、2、3…),凡报5的倍数者出圈,剩下者继续报数,求出最后出圈者的编号。
#include main ( ) { int
a[26], j,n, count; for (j=1; j<=25; j++)
a[j]=j; j=1;count=0;n={{U}} {{U}}
{{/U}} {{/U}}; do {
if(a[j] !=0)
{ n++;
if (n%5==0)
{ {{U}} {{U}} {{/U}}
{{/U}};
if(count==24) printf("%d/n",,j);
count++;
} }
j++; if (j>25) j=1;
} while({{U}} {{U}} {{/U}} {{/U}});
}
填空题若有如下程序: sub(int*y) while(--(*y)); printf("%d",(*y)--); main() int x=10; sub(&x); 则程序运行后的输出结果是 【13】 。
填空题下列给定程序中,函数proc()的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数(参数num)为止。
π/4≈1-1/3+1/5-1/7+…
例如,程序运行后,输入0.0001,则程序输出3.1414。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
float proc(float num)
{
int s;
float n,t,pi;
t=1;pi=0;n=1;s=1;
//****found****
while(t>=num)
{
pi=pi+t;
n=n+2;
s=-s;
//****found****
t=s%n;
}
pi=pi*4;
return pi;
}
void main()
{
float n1,n2;
system("CLS");
printf("Enter a float number:");
scanf("%f",
n2=proc(n1);
printf("%6.4f/n",n2);
}
填空题以下程序运行后的输出结果是______。
main()
{
int a,b,c;
a = 25;
b = 025;
c = 0x25;
printf("%d %d %d/n",a,b,C) ;
}
填空题下面程序用来输出结构体变量a所占存储单元的字节数,请填空。 main() struct stu char x[20];float y; a; printf("a size:%d/n",sizeof( 【14】 ));
填空题有以下程序:
#include <stdio.h>
main()
{ char ch1,ch2;int n1,n2;
ch1=getchar();ch2=getehar();
n1=ch1-'0'; n2=n1*10+(ch2-'0');
printf("%d/n",n2);
}
程序运行时输入:12<回车>,执行后的输出结果是{{U}} 【9】 {{/U}}。
填空题函数main()的功能是在带头结点的单链表中查找数据域中值最小的结点。请填空。 #include<stdio.h> struct node int data; struct node*next: ; int min(struct node*first)/*指针first为链表头指针*/ strct node *p;int m; p=first->next;m=p->data;p=p->next; for(; p!=NULL;p=) if(p->datadata<m)m=p->data; return m;
填空题下列给定程序中函数fun的功能是:求三个数的最小公倍数。
例如,若给主函数中的变量x1、x2、x3分别输入15112,则输出结果应当是330。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
/**********found**********/
fun(int x, y, z)
{
int j, t, n, m;
j=1;
t=j%x; m=j%y;
n=j%z;
while(t!=0||m!=0||n!=0)
{
j=j+1;
t=j%x;
m=j%y;
n=j%z;
}
/**********found**********/
return i;
}
main()
{
int x1, x2, x3, j;
printf("Input x1 x2 x3:");
scanf("%d%d%d",
printf("x1=%d, x2=%d, x3=%d/n", x1, x2, x3);
j=fun(x1, x2, x3);
printf("The minimal common multiple is: %d/n", j);
}
填空题给定程序中,函数fun的功能是:将形参s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。
例如,形参s所指的字符串为abs5def126jkm8,程序执行后的输出结果为22。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char*s)
{int sum=0;
while(*s){
/*********found*********/
if(isdigit(*s))
sum+=*s-______;
/*********found*********/
______;
}
/*********found*********/
return ______;
}
main()
{char s[81]; int n;
printf("/nEnter a string:/n/n");
gets(s);
n=fun(s);
printf("/nThe result is:%d/n/n",n);
}
填空题以下程序运行后的输出结果是{{U}} 【9】 {{/U}}。
main()
{int X==1,y=0,a=0,b=0;
switch (x)
{case 1:switch (y)
{ case 0:a++;break;
case 1:b++;break;
}
case 2: a++;b++;break;
}
printf("%d%d/n",a,b);
}
填空题请补充函数fun(),该函数的功能是:只保留字符串中的大写字母,删除其他字符,结果仍保存在原来的字符串中,由全局变量m对删除后字符串的长度进行保存。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #include<conio.h> int m; void fun(char *s) int i=0,j=0; char *p=s; while (*(p+i)) if(*(p+i)>='A' 【3】 ; main() char str[80]; clrscr(); printf("/nEnter a string:"); gets(str); printf("/n/nThe string is:/%s/n",str); fun(str); printf("/n/nThe string of changing is:/%s/n",str); printf("/n/nThe length of changed string is:/%d/n",m);
填空题已有定义如下:
struct node
{ int data;
struct node *next;
} *p;
以下语句调用malloc函数,使指针p指向一个具有struct node类型的动态存储空间。请填空。 p = (struct node *)malloc(【 】);
填空题设a,b,c为整型数,且a=2,b=3,c=4,则执行完以下语句后,a的值是 【8】 。 a*=16+(b++)-(++c);
填空题若输入5、9,以下程序的运行结果为 【10】 。main() int a,b,*pt1,*pt2; printf("input a,b:"); scanf("%d%d",&a,&b); pt1=&a; pt2=&b; if(a<b) swap(pt1,pt2); printf("/n%d,%d/n",*pt1,*pt2);swap(p1,p2)int *p1,*p2; int *p; p=p1; p1=p2; p2=p;
