当前位置:首页 > C08试卷A
}
3. 下列程序的输出结果是__________。
#include
4. 运行下面程序的输出结果是__________。
#include
void p(int x, int *y) { int z; ++x; ++*y; z=x+*y; w+=x;
printf(“%d#%d#%d#%d#”, x,*y,z,w); }
main()
{ x=y=z=w=1; p(y, &x);
printf(“%d#%d#%d#%d#”, x,y,z,w); }
5. 下列程序运行时输入:C Java C++ VB Fortran #include
《程序设计基础及实验》课程期末考试试卷, 2009年1月15日 回车>,输出结果为_______。 5 / 8
Basic <
char *p=str; int k1=0,k2=0; while(1) {
if(*p!=' ' && *p!='\\t' && *p!='\\0') k2++; else { if (k2>k1) { k1=k2; str=p-k2;} k2=0; if (*p=='\\0') break; } p++; }
for(k2=0;k2 main() { char a[80]; gets(a); find(a); } 6. 下列程序运行时输入:8 3 7 2 1 8 3 4 1 <回车>,输出结果为_______。#include int i, n, a[10]; scanf(\ for (i=0; i scanf(\ f(a+n/4,n/2); for (i=0; i printf(\} void f(int a[], int n) { int i, j, temp; 《程序设计基础及实验》课程期末考试试卷, 2009年1月15日 6 / 8 for( i = 1; i < n; i++) for (j = 0; j < n-i; j++ ) if (a[j] > a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } 试题四、程序(段)填空题(每空2分,共20分) 1. 下面的函数将数组a(大小为n)中的整数按原有顺序构造成一个链表,并判别该链表中的数据是 否是递增顺序,若是则返回1,否则返回0。 int f(int a[], int n) { struct node { int info; struct node *next; } *h=NULL, *q=NULL, *p; int i; for(i=0; i p=(struct node *)malloc( (1) ); p->info= (2) ; if (q!=NULL) q->next=p; else { h=p; } q= (3) ; } p->next=NULL; /* 以下程序段为:判别h所指向的链表数据是否成递增序列 */ q=h; if (q==NULL || q->next==NULL) return 1; p=q->next; while ((p!=NULL) && (p->info > q->info)) { q=p; p= (4) ; } if (p==NULL) return 1; else (5) ; } 2. 下面的程序通过命令行参数方式比较两个文本文件是否完全相同,比较方式prog file1 file2。 #include main(int argc, char *argv[]) { FILE *fp1, *fp2; char c1, c2; 《程序设计基础及实验》课程期末考试试卷, 2009年1月15日 7 / 8 if (argc!= (6) ) { printf(\ file1 file2\\n\ exit(0); } if ((fp1=fopen(argv[1], \ || (7) ) { printf(\ exit(0); } c1=fgetc(fp1); c2=fgetc(fp2); while ( (8) && c1==c2) { c1=fgetc(fp1); c2=fgetc(fp2); } if ( (9) ) printf(\else printf(\ (10) fclose(fp2); return 0; } 1 A 2 B 3 C 4 A 5 D 6 B 7 D 8 B 9 D 10 C 1 4 2 20 3 ac 4 5#5# 5 1#3#5# 6 abc#123# 7 *s++=*t++ 8 i=0, s=0; i<10; s+=a[i++] 9 -3 10 0 11 typedef int *AIP[10] 12 ef 《程序设计基础及实验》课程期末考试试卷, 2009年1月15日 8 / 8
共分享92篇相关文档