计算机上机题库.docVIP

  • 77
  • 0
  • 约 77页
  • 2016-12-21 发布于贵州
  • 举报
一、程序改错题。 gc22.c程序是输入一个字符串, 将此字符串中最长的单词输出,程序在注释行附近有两个错误,请试调试改正,但调试改正中不得增删语句。 int alph(char c) { if((c=ac=z)||(c=Ac=Z)) return(1); else return(0); /* find 1 */ } int longest(char *str) //int longest(char str) { int len=0,i,length=0,flag=1,point,place; for(i=0;i=strlen(str);i++) if(alph(str[i])) if(flag) { flag=0; point=i; } else len++; else /* Find 2 */ { flag=1; //flag=0; if(lenlength) { length=len; place=point; len=0; } } return(place); } main( ) { int i; char line[100]; printf(Enter string\n); gets(line); printf(the longest is:); for(i=longest(line);alph(line[i]);i++) printf(%c,line[i]); printf(\n); } 二、程序填空题 tk22.c是打印出杨辉三角形,在空白处将程序补充完整,运行得出正确结果。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 . . . #define N 11 main( ) { int I,j,a[N][N]; for (I=1; IN; I++) { a[I][I]=1; a[I][1]=1; // } for (I=3;IN; I++) for ( j=2;jI;j++ )// a[I][j]=a[I-1][j-1]+a[I-1][j]; for (I=1;IN;I++) { for (j=1;j=I;j++) printf(%6d,a[I][j]); printf(\n); } printf(\n); } 一、程序改错题(20分)。 下列程序是建立一个包含学生有关数据的单向链表。但该程序有2个错误,错误出现在每个注释行附近,请调试改正。调试改正中,不得改变程序结构,也不得增删语句。 #define NULL 0 struct stud { long num; char name[10]; float score; struct stud *next; }; /* …………… comment …………… */ int n; struct stud create() { struct stud *head,*p1,*p2; n=0; p1=p2=(struct stud *)malloc(sizeof(struct stud)); scanf(%ld,%s,%f,p1-num,p1-name,p1-score); /* ……………comment …………… */ head=NULL; while(p1!=0) { n=n+1; if(n==1) head=p1; else p2-next=p1; p1=(struct stud *)malloc(size(struct stud)); scanf(%ld,%s,%f,p1-num,p1-name,p1-score); } p2-next=NULL; return(head); } 二、程序填空题(20分)。 下面的程序是完成从键

文档评论(0)

1亿VIP精品文档

相关文档