填空题以下程序由终端键盘输入一个文件名,然后把从终端键盘输入的字符依次放到该文件中,用井作为结束输入的标志。请填空。 # include<stdio.h> main( ) FILE * fp; char ch,fname[10]; printf("Input the name of file/n"); gets(fname); if((fp= 【16】 )==NULL) printf("Can not ope/n");exit(O); printf("Enter data/n"); while((ch=getchar())!=' # ') fputc( 【17】 ,fp); fclose(fp);
填空题以下程序的功能是:对输入的一行字符串的数字字符按它们的字面值累加,输出此累加和。例如,输入一行字符是:ab34dh8u,输出值应当是15。请填空。 #include <stdio.h> #include <ctype.h> main() char ch; int a,s; 【11】 ; while((ch=getchar()) 【12】 ) if( isdigit (ch)) a= 【13】 ;s+=a; printf("s=%d/n/n",s);
填空题下列程序的运行结果是{{U}} 【10】 {{/U}}。
#include <stdio.h>
main()
{ union EXAMPLE
{ struct
{ int x; int y;} in;
int a;
int b;
}e;
e.a=1;e.b=2;
e.in.x=e.a*e.b;
e.in.y=e.a+e.b;
printf("%d,%d/n",e.in.x,e.in.y);
}
填空题以下程序运行后的输出结果是______。 #include<stdio.h> main() int a=37; a%=9;printf("%d/n",a);
填空题有以下程序: #include<stdio.h> #include<string.h> void fun(char*str) char temp;int n,i; n=strlen(str); temp=str[n-1]; for(i=n-1;i>0;i--)str[i]=str[i-1]; str[0]=temp; main() char s[50]; scanf("%s",s);fun(s);printf("%s/n",s); 程序运行后输入:abcdef<回车>,则输出结果是______。
填空题下列给定程序中,函数proc()的功能是:从m个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
60 70 80 90 65 75 85 95
则低于平均分的学生人数为4(平均分为77.5)。实际输入时学生数以回车键作为结束,成绩与成绩之间也与回车键作为分隔。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#inelude<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 20
int proc (float *s, int n, float * aver)
{
//************found*************
int ave, t=0;
int count=0, k, i;
for(k=0; k<n; k++)
t+=s[k];
ave=t/n;
for(i=0; i<n; i++)
//************found************
if(s[i]>ave)
count++;
//************found*************
aver=ave;
return count;
}
void main()
{
float stu[30], aver;
int m, i;
system("CLS");
printf("/nPlease enter m: ");
scanf("%d", &m);
printf("/nPlease enter%d mark: /n", m);
for(i=0; i<m; i++)
scanf("%f", stu+i);
printf("/nThe number of students: %d/n",
proc(stu, m, &aver));
printf("Ave=%f/n", aver);
}
填空题给定程序中,函数fun的作用是:不断从终端读入整数,由变量a统计大于0的个数,用变量c来统计小于0的个数,当输入0时结束输入,并通过形参pa和pb把统计的数据传回主函数进行输出。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
void fun(int*px,int*py)
{
/**********found**********/
int ______;
scanf("%d",
/**********found**********/
while ______
{if(k>0)a++;
if(k<0)b++;
/**********found**********/
______;
}
*px=a;*py=b;
}
main()
{int x,y;
fun(
printf("x=%d y=%d/n",x,y);
填空题请补充main()函数,该函数的功能是:先以只写方式打开文件“out.dat”,再把字符串str中的字符保存到这个磁盘文件中。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 80
void main ()
{ FILE*fp;
int i=0;
char ch;
str[M]="I"m a student!";
system("CLS");
if((fp=fopen(______))==NULL)
{
printf("cannot open out.dat/n");
exit(0);
}
while (str[i])
{
ch=str[i];
______;
putchar(ch);
i++;
}
______;
}
填空题有以下程序:
main()
{ int a=7,b=8,*p,*q,*r;
p= q=
r=p; p=q; q=r;
printf("%d,%d,%d,%d/n",*p,*q,a,b);
}
程序运行后的输出结果是{{U}} 【5】 {{/U}}。
填空题下列程序的输出结果是{{U}} 【13】 {{/U}}。
void fun(int*n)
{while ((*n)--);
printf("%d",++(*n));
}
main()
{ int a=1000;
fun(
}
填空题以下程序的功能是:求出数组x中各相邻两个元素的和依次存放到a数组中,然后输出。请填空。 main( ) int x[10],a[9],i; for(i=0;i<10;i++) scanf("%d",&x[i]); for( [11] ;i<10;i++) a[i-1]=x[i]+ [12] ; for(i=0;i<9;i++) printf("%d",a[i]); printf("");
填空题以下程序的输出结果是{{U}} 【11】 {{/U}}。
# define MCNA(m)2*m
# define MCNB(n, m)2*MCRA(n)+m
# define f(x)(x*x)
main()
{ int i=2, j=3;
printf("% d/n", MCRB(j, MCRA(i)));
}
填空题有如下图所示的双链表结构,请根据图示完成结构体的定义:structaa{intdata;{{U}}【15】{{/U}}}node;
填空题以下程序运行后的输出结果是______。 main() int a[4][4]=1,2,3,4),5,6,7,8,11,12,13,14,15,16,17,18; int i=0,j=0,s=0; while (i++<4) if (i==2 || i==4)continue; j=0; do S+= a[i][j] ;j++; while (j<4); printf("%d/n",s);
填空题下面程序的运行结果是: 【19】 。 typedef union student char name[10]; long sno; char sex; float score[4]; STU; main() STU a[5]; Printf(“%d/n”,sizeof(a));
填空题程序的功能是将文件filel.c的内容输出到屏幕上并复制到文件file2.c中,请填空。
#include<stdio.h>
main()
{ FILE {{U}}【19】 {{/U}};
fp1=fopen("filel.c","r");
fp2=fopen("file2.c","w");
while(!feof(fp1)) putchar(getc(fp1));
rewind(fp1);
while(!feof(fp1)) putc({{U}} 【20】 {{/U}});
fclose(fp1);
fclose(fp2);
}
填空题以下程序运行后的输出结果是______。
#include<string.h>
#include<stdio.h>
main()
{ char s[20]="goodgood!", *sp=s;
sp=sp+2; sp="to"; puts(s);
}
填空题以下程序用业统计文件十字符个数。请填空。 #include "stdio.h" main() FTLE *fp; long num=OL; if((fp=fopen("fname.dat","r"))==NUlL) pirntf("Open error/n"); exit(0); while( ) fgetc(fp); num++; printf("num=%1d/n",num-1); fclose(fp);
填空题int *p 的含义是___________________________________________。
填空题下列给定程序中,函数fun()的功能是:在带头结点的单向链表中,查找数据域中值为ch的结点。找到后通过函数值返回该结点在链表中所处的顺序号;若不存在值为ch的结点,函数返回0值。
请在标号处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构。
试题程序 #include
<stdio.h> #include <stdlib.h> #define N
8 typedef struct list { int data;
struct list *next; } SLIST; SLIST
*creatlist(char *); void outlist(SLIST *); int
fun( SLIST *h, char ch) { SLIST *p; int n=0;
p=h->next; while(p!=______) { n++;
if(p->data==ch) return______; else p=p->next;
} return 0; }
main() { SLIST *head; int k; char ch; char
a[N]={'m', 'p', 'g', 'a', 'w', 'x', 'r', 'd'};
head=creatlist(a); outlist(head);
printf("Enter a letter:"); scanf("% c",
k=fun(______); if(k==0) printf("/nNot found!
/n"); else printf("The sequence number is:%
d/n", k); } SLIST *creatlist(char
*a) { SLIST *h, *p, *q; int i; h=p=(SLIST *)
malloc (sizeof(SLIST)); for(i=0; i<N; i++) {
q=(SLIST *) malloc (sizeof(SLIST)); q->data=a[i]; p->next=q;
p=q; } p->next=0; return
h; } void outlist(SLIST *h) {
SLIST *p; p=h->next; if(p==NULL)
printf("/nThe list is NULL! /n"); else
{ printf("/nHead"); do { printf("->%
c", p->data); p=p->next; }
while(p!=NULL); printf("->End/n"); }
}
