填空题下列程序段中循环体的执行次数是______;
a=15;
b=0;
do{b+=2;a-=2+b;}while(a>=0);
填空题以下程序运行后的输出结果是 【8】 。 main() int a=1,b=3,c=5; if(c=a+b) printf("yes/n"); else printf("no/n");
填空题下面函数要求计算两个整数x,y之和,并通过形参返回该值,请填空。
add(int x,int y,{{U}} 【16】 {{/U}}z)
{ {{U}}【17】 {{/U}}=x+y;}
填空题给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#define N 5
#define M 8
void fun (char(*ss)[M])
{char*ps[N],*tp;int i,j,k;
for(i=0;i<N;i++)
ps[i]=ss[i];
for(i=0;i<N-1;i++){
/*********found*********/
k=______;
for(j=i+1;j<N;j++)
/*********found*********/
if(strlen(ps[k])<strlen(______))k=j;
/*********found*********/
tp=ps[i];ps[i]=ps[k];
ps[k]=______;
}
printf("/nThe string after sorting by length:/n/n");
for(i=0;i<N;i++)puts(ps[i]);
}
main()
{char ch[N][M]={"red","green","blue","yellow","black"};
int i;
printf("/nThe original string/n/n");
for(i=0;i<N;i++)
puts(ch[i]);printf("/n");
fun(ch);
}
填空题在内存中,存储字符'x'要占用1个字节,存储字符串"X"要占用 【11】 个字节。
填空题若有以下函数定义,函数返回值的类型是{{U}} 【7】 {{/U}}。
fun(double A)
{return a*a*a;}
填空题下面程序的功能是建立一个有3个结点的单循环链表,如下图所示然后求各个结点数值域data中数据的和,请填空。#include<stdio.h>#includestructNODEintdata;structNODE*next;;main()structNODE*p,*q,*r;intsum=0;p=(structNODE*)malloc(sizeof(structNODE));q=(structNODE*)malloc(sizeof(structNODE));r=(structNODE*)malloc(sizeof(structNODE));p->data=100;q->data=200;r->data=300;p->next=q;q->next=r;r->next=p;sum=p->data+p->next->data+r->next->next______;printf("%d/n",sum);
填空题以下程序的运行结果是 【17】 。 #include <stdio.h> #include <string.h> typcdef struct student char name[10]; long sno; float score; STU; main() STU a="Zhangsan",2001,95,b="Shangxian",2002,90, c="Anhua",2003,95,d,*p= d=a; if(strcmp(a.name,b.name)>0) d=b; if(strcmp(c. name,d. name)>0)d=c; printf("%1d%s/n",d.sno,p->name);
填空题下列程序的输出结果是 【6】 main( ) int a=1,b=2; a= a + b;b=a-b;a=a-b; printf("%d,%d/n",a,b);
填空题下面程序的功能是{{U}} 【12】 {{/U}}。
double sub(double x,int y)
{int n; double z;
for(n=1,z=x;n<y;n++) z=z* x;
return z; }
main()
{double a=2.0,b=4.0,c;
c=sub(a,b) ; printf("%f",c) ; }
填空题以下程序的功能是计算:s=1+12+123+1234+12345。请填空。
main()
{ int t=0,s=0,i;
for(i=1;i<=5;i++)
{t=i+{{U}} 【10】 {{/U}};s=s+t; }
printf("s=%d/n",s);
}
填空题请补充main函数,该函数的功能是:把字符串str中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。
例如,输入“how do you do?”,则结果输出“ow do you do?h”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio. h>
#define N 80
main()
{
char str[N], ch;
int i;
clrscr ();
printf("/n Input a string:In");
gets (str);
printf("/n*** original string ***In");
puts (str);
ch=str [0];
for (i=0; {{U}}【1】 {{/U}}; i++)
str [i]=str [i+1];
{{U}} 【2】 {{/U}};
printf("/n *** new string ***/n");
puts (str);
}
填空题若要使指针p指向一个double类型的动态存储单元,请填空。 p= 【11】 malloc(sizeof(double));
填空题以下程序的输出结果是{{U}} {{U}} {{/U}} {{/U}}。
#include <stdio.h>
#define M 5
#define N M+M
main0
{ int k;
k = N'N*5; printf("%d/n",k);
}
填空题给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node{
int data;
struct node *next;
}NODE;
void fun(NODE *h)
{NODE *p,*q,*r;
/**********found**********/
p=h->______;
/**********found**********/
if(p==______)return;
q=p->next;
p->next=NULL;
while(q)
{r=q->next;q->next=p;
/**********found**********/
p=q;q=______;
}
h->next=p;
}
NODE*creatlist(int a[])
{NODE*h,*p,*q;int i;
h=(NODE*)malloc(sizeof(NODE));
h->next=NULL;
for(i=0;i<N;i++)
{q=(NODE*)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h->next==NULL)h->next=p=q;
else{p->next=q;p=q;}
}
return h;
}
void outlist(NODE *h)
{NODE *p;
p=h->next;
if(p==NULL)printf("The list is NULL!/n");
else
{printf("/nHead");
do
{printf("->%d",p->data);p=p->next;
}
while(p!=NULL);
printf("->End/n");
}
}
main()
{NODE*head;
int a[N]={2,4,6,8,10};
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after inverting:/n");
outlist(head);
}
填空题有以下程序: main() int a[]=1, 2, 3, 4, 5, 6, 7, 8, 9, 0, *p; for(p=a; p<a+10; p++)printf("% d,", *p); 程序运行后的输出结果是 【10】 。
填空题下述函数通过递归方法将字符串倒置,使用时需要指定字符数组的首地址、起始下标和终止下标。请填空: #include<stdio.h> void fun(char *s,int low,int high) if( 【12】 ) return; else char t; fun( 【13】 ); t=s[low]; s[low]=s[high]; s[high]=t;
填空题若有定义:int a=10,b=8,c=4;然后顺序执行下列语句后,变量a中的值是______。 c=(b-=(a-4));a=(c%2)+(b-1);
填空题以下程序运行时若从键盘输入:10 20 30<回车>,输出结果是{{U}} {{/U}}。 # include<stdio.h> main() int i=0,j=0,k=0; scanf("%d% *d%d",printf("%d %d %d//n",i,j,k);
填空题以下程序的功能是:通过函数func输入字符并统计输入字符的个数。输入时用字符@作为输入结束标志。请填空。
#include <stdio.h>
long{{U}} 【14】 {{/U}}; /*函数说明语句*/
main()
{ long n;
n=func(); printf("n=%1d/n"n);
}
long func()
{ long m;
for( m=0;getchar()!=@{{U}} 【15】 {{/U}};
return m;
}
