填空题下面程序的功能是根据公式e=1+1/1!+1/2!+1/3!+1/4!+...计算e的近似值,精度要求为10-5。请填空。 main() int n; double e=1.0,t=1.0; for(n=1; 【7】 n++); 【8】 e+=t; printf("%f/n",e);
填空题设在主函数中有以下定义和函数调用语句,且fun函数为void类型;请写出fun函数的首部 【9】 ,要求形参名为b。 main() double s[10][22]; int n; … fun(s); …
填空题理解下面的程序,填空完善程序。 main( ) int a,b,c; scanf("%d%d", 【12】 ); c= 【13】 (a,b); printf("a=%d b=%d max=%d/n",a,b,c); int max(x,y) 【14】 ; int z; if(x>y) z=x; else z=y; 【15】 ;
填空题已知字符A的ASCII代码值为65,以下程序运行时若从键盘输入:B33<回车>,则输出结果是
{{U}} 【11】 {{/U}}。
#include <stdio.h>
main()
{ char a,b;
a=getchar();scanf("%d",b=b*2;
printf("%c%c/n",a,b);
}
填空题若有定义语句char s[100],d[100];int j=0,i=0;且s中已赋字符串,请填空以实现拷贝。 (注:不使用逗号表达式) while(s[i])(d[j]= 【10】 ;j++; d[j]=0;
填空题程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。所有学生数据均以二进制方式输出到文件中。函数fun的功能是重写形参filename所指文件中最后一个学生的数据,即用新的学生数据覆盖该学生原来的数据,其他学生的数据不变。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
源程序如下:
#include<stdio.h>
#define N 5
typedef struct student{
long sno;
char name[10];
float score[3];
}STU;
void fun(char*filename, STU n)
{FILE*fp;
/*********found*********/
fp=fopen(______, "rb+");
/********found********/
fseek(fp, -1L*sizeof(STU), ______);
/********found********/
fwrite(______,sizeof(STU), 1, fp);
fclose(fp);
}
main()
{ STU t[N]={{10001, "MaChao", 91, 92, 77}, {10002, "CaoKai", 75, 60, 88},
{10003, "LiSi", 85, 70, 78}, {10004, "FangFang", 90, 82, 87},
{10005, "ZhangSan", 95, 80, 88}};
STU n={10006, "ZhaoSi", 55, 70, 68}, ss[N];
int i,j; FILE *fp;
fp = fopen( " student, dat" ," wb" );
fwrite ( t, sizeof( STU ) , N, fp);
fclose ( fp ) ;
fp = fopen( " student, dat" ," rb" );
fread ( ss, sizeof( STU ) , N, fp);
fclose ( fp );
printf( " /nThe original data : /n/n" );
for (j=0; j<N; j++)
printf( "/nNo: % ld Name: % -8s Scores: ", ss[j]. sno, ss[j], name);
for (i=O; i<3; i++)printf("%6.2f" ,ss[j]. score[i] );
printf( "/n" );
fun( "student, dat" , n);
printf( "/nThe data after modifing : /n/n" );
fp = fopen( "student, dat", " rb" );
fread ( ss, sizeof( STU ), N, fp );
fclose ( fp );
for (j=0; j<N; j++)
printf( "/nNo: % ld Name: %-8s Scores: ", ss[j]. sno, ss[j], name);
for (i=0; i<3; i++) printf("%6.2f" , ss[j]. score[i] );
printf( "/n" );
}
}
填空题以下程序运行后的输出结果是______。 main( ) int x=10,y=20,t=0; if(x= =y)t=x;x=y;y=t printf("%d,%d/n",x,y);
填空题下面程序的运行结果是______。 ##include<stdio.h> main() int a,s,n,m; a=2;s=0;n=1;m=1; while(m<=4)n=n*a;s=s+n;++m; printf("s=%d",s);
填空题下面程序段的输出结果是 【6】 。 int i=0,sum=1; do sum += i+ +; while(i<6); print("%d/n",sum);
填空题给定程序中,函数fun()的功能是将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。例如,形参s所指的字符串为def35adh3kjsdf7,执行结果为defadhkjsdf3537。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构。 #include<stdio.h> void fun(char *s) int i,j=0,k=0;char t1[80],t2[80]; for(i=0;s[i]!='/0';i++) if(s[i]>='0'0 (1) ; else t1[k++]=s[i]; t2[j]=0;t1[k]=0; /**********found**********/ for(i=0;i<k;i++) (2) ; /**********found**********/ for(i=0;i< (3) ;i++)s[k+i]=t2[i]; main() char s[80]="ba3a54j7sd567sdffs"; printf("/nThe original string is:%s/n",s); fun(s); printf("/nThe result is:%s/n",s);
填空题请补充main()函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1指向原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。
例如,当str1="abcdefghi",然后输入7,则str2="abcdefg"。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define N 80
void main()
char str1[N],str2[N];
int n,i;
system("CLS");
printf("Enter the string:/n");
gets(str1);
printf("Enter the position of the string deleted:");
scanf(______);
for(i=0;i<n;i++)
______
str2[i]="/0";
printf("The new string is:%s/n",______);
}
填空题在面向对象方法中,允许作用于某个对象上的操作称为{{U}} 【2】 {{/U}}。
填空题有以下程序: int f(int b[][4]) int i,j,s=0; for(j=0;j<4;j++) i=j; if(i>21)=3-j; s+=b[i][j]; return S; main() int a[4][4]=(1,2,3,4),(0,2,4,6),(3,6,9,12),(3.2,1,0); printf(“%d/n”.f(a)) 执行后的输出结果是[12]。
填空题以下程序运行的结果是 【14】 。 #include<conio.h> #include<stdio.h> #define M 100 void fun(int m,int*a,int*n) int i,j=0; for(i=1;i<=m;i++) if(i%7==0‖i%11==0) a [j++]=i; *n=j; main() int aa[M],n,k; clrscr(); fun(10,aa,&n); for(k=0;k<n;k++) if((k+1)%20==0)printf("/n"); else printf("%4d",aa[k]); printf("/n");
填空题若有程序
main( )
{ int i,j;
scanf("i=%d,j=%d",
printf("i=%d,j=%d/n ",i,j);
}
要求给i赋10,给j赋20,则应该从键盘输入【 】。
填空题以下程序的作用是:从名为filea.dat的文本文件中逐个读入字符并显示在屏幕上。请填空。 #include <stdio.h> main() FILE *fp; char ch; fp=fopen( 【15】 ); ch=fsetc(fp); while(! feof (fp)) putchar(ch); ch=fgetc(fp); putchar('/n'); fclose(fp);
填空题下面invert函数的功能是将一个字符串str的内容颠倒过来,请填空。 #include<string.h> void invert(char str[]) int i,j, 【17】 ; for(i=0,j=strlen(str) 【18】 ;i<j;i++,j--) k=str[i];str[i]=str[j];str[j]=k;
填空题阅读下列程序,则程序的输出结果为 【16】 。 #include"stdio.h" struct ty int data; char c;; main() struct ty a=30,'x'; fun(a); printf("%d%c",a.data,a.c); fun(struct ty b) b.data=20; b.c='y';
填空题设有如下定义 #define MYSWAP(z,x,y) z=x; x=y; y=z; float a=5,b=16,c; MYSWAP(______,a,b);
填空题已知字符'A'的ASCII码为65,以下程序运行后的输出结果是 【9】 。#include <stdio.h> main( ) char a,b; a='A'+'5'-'3'; b=a+'6'-'2'; printf( "% d% c/n", a, b);
