当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C语言程序设计》课程教学资源:练习题-B

资源类别:文库,文档格式:DOC,文档页数:5,文件大小:42KB,团购合买
一、简答题(共5题,每题4分,共20分) 1、写出判断一个整形变量κ能被5整除但不能被7整除的逻辑表达式 2、用循环语句编程实现从二维数组 a[3][4]={{2,4,5,7},{3,12,8,11},{8,1,0,19},{10,6,15,13 };中找出最大数 3、下面程序中的swap函数能否实现变量a和b值的互换,如不能,请重新编写一个函数实现变量a和b值的互换。
点击下载完整版文档(DOC)

、简答题(共5题,每题4分,共20分) 1.写出判断一个整形变量ⅹ能被5整除但不能被7整除的逻辑表达式。 2.用循环语句编程实现从二维数组 Int a[3][4]={{2,4,5,7},{3,12,8,11},{8,1,0,19},{10,6,15,13} };中找出最大数 3.下面程序中的swap函数能否实现变量a和b值的互换,如不能,请重 新编写一个函数实现变量a和b值的互换。 void swap(int x, int y) main () printf(岩d,号dn 4.写出下面程序运行输出的结果。 inta[j={1,2,3,4,5,6,7,8,9,10,11,12} int *p=a+5,*g=NULL gp printf("岩d号d\n",*,*q); 5.有下列C语句 struct table unsigned int typei } table1={3456,455.50} struct ptab ptab=&tableli 写出使用结构变量名和指向结构的指针两种方法在屏幕上分别输出结构变 量成员的C语句 、完成下列程序缺少部分(共5题,每题4分,共20分)

一、 简答题(共 5 题,每题 4 分,共 20 分) 1. 写出判断一个整形变量 x 能被 5 整除但不能被 7 整除的逻辑表达式。 2. 用循环语句编程实现从二维数组 int a[3][4]={{2,4,5,7},{3,12,8,11},{8,1,0,19},{10,6,15,13} };中找出最大数。 3. 下面程序中的 swap 函数能否实现变量 a 和 b 值的互换,如不能,请重 新编写一个函数实现变量 a 和 b 值的互换。 void swap(int x,int y) { int temp; temp=x; x=y; y=temp; } main() { int a=4,b=8; swap(a,b); printf(“%d,%d\n”,a,b); } 4. 写出下面程序运行输出的结果。 main( ) { int a[ ]={1,2,3,4,5,6,7,8,9,10,11,12}; int *p=a+5, *q=NULL; q=p+5; printf("%d %d \n",*p,*q); } 5. 有下列 C 语句: struct table { unsigned int type; float price; }table1={3456,455.50}; struct * ptab; ptab=&table1; 写出使用结构变量名和指向结构的指针两种方法在屏幕上分别输出结构变 量成员的 C 语句。 二、 完成下列程序缺少部分(共 5 题,每题 4 分,共 20 分)

1.函数fun的功能是:使一个字符串按逆序存放,str1en()函数的功能是计 算字符串的长度,完成函数下划线部分。 Ld fun(char str[]) t for(i=0,j=strlen(str)ii< m=str[i] strip= printf("号s\n",Str); 以下程序中,主函数调用了 Cinemax函数,实现在N行M列的二维数组中, 找出每一行上的最大值。完成函数中的下划线部分。 #define M 4 void LineMax(int x[N][M]) int l,],p for (i=0; i<N;i++) p=0; if(x[i][p]<x[i][]) printf(" The max value in1ine暑dis各d\n",i, 3. mystrlen函数的功能是计算str所指字符串的长度,并作为函数值返回。 完成函数中的下划线部分 int mystrlen(char *str lint l; =1\0′;i++); return( 4.函数fun的功能是:累加数组元素的值。n为数组中元素的个数,累加和的 值放入x所指的存储单元中,完成函数中下划线部分。 void fun(int b[], int n, int int k,r=0; for (k=0i k<n; k++)

1. 函数 fun 的功能是:使一个字符串按逆序存放, strlen()函数的功能是计 算字符串的长度,完成函数下划线部分。 void fun(char str[]) { char m; int i,j; for(i=0,j=strlen(str);i< ;i++,j--) { m=str[i]; str[i]= ; str[j-1]=m; } printf("%s\n",str); } 2. 以下程序中,主函数调用了 LineMax 函数,实现在 N 行 M 列的二维数组中, 找出每一行上的最大值。完成函数中的下划线部分。 #define N 3 #define M 4 void LineMax(int x[N][M]) { int i,j,p; for(i=0; i<N;i++) { p=0; for(j=1;j<M;j++) if(x[i][p]<x[i][j]) ; printf("The max value in line %d is %d\n", i, ); } } 3. mystrlen 函数的功能是计算 str 所指字符串的长度,并作为函数值返回。 完成函数中的下划线部分。 int mystrlen(char *str) { int i; for(i=0; !=’\0’;i++); return( ); } 4. 函数 fun 的功能是:累加数组元素的值。n 为数组中元素的个数,累加和的 值放入 x 所指的存储单元中,完成函数中下划线部分。 void fun(int b[],int n,int * x) { int k,r=0; for(k=0;k<n;k++)

5.下面程序是输出结构数组中所有学生的姓名和成绩。完成程序中下划线部 分 struct studenti char name [20] float score struct student stus [5]=f["Liping",85.5,Zhanghao,90.0 I"Wangmin",75),I"Denglan",95),i" Maming",84.5) main p for(p stus; p++) printf(“号s暑f p->score) 、编程题(10分) 有一段关于c语言的文字,共有3行,每行最多有80个字符,编程统计出这段 文字的大写英文字符、小写英文字符、数字、空格和其它字符的个数并将统计结 果输出。 char text[ tThe programming language c was originally developed by Dennis Ritchie of bell Laboratories and was designed to run on a PDP-11 with a UNIX operating system.)

r= ; _________________= r; } 5. 下面程序是输出结构数组中所有学生的姓名和成绩。完成程序中下划线部 分。 struct student{ char name[20]; float score; }; struct student stus[5]={{”Liping”,85.5},{”Zhanghao”,90.0}, {”Wangmin”,75},{”Denglan”,95},{”Maming”,84.5}}; main() { struct student * p; for(p = stus; ; p++) printf(”%s %f\n”, ,p->score) } 三、 编程题(10 分) 有一段关于 c 语言的文字,共有 3 行,每行最多有 80 个字符,编程统计出这段 文字的大写英文字符、小写英文字符、数字、空格和其它字符的个数并将统计结 果输出。 char * text[]= {”The programming language C was originally developed ”, ”by Dennis Ritchie of Bell Laboratories and was designed ”, ”to run on a PDP-11 with a UNIX operating system.”};

答案: 简答题(共5题,每题4分,共20分) 1.(x85==0)&(x号7!=0)或x号5==0医x号7!=0或!(x号5)&医x号7 分分分 (全对4分,否则按上面给分) 答 max=a[0][0]; for(i=0;1max) (1分) ax=a[i][3li 不能。 ….(1分 void swap(int * x, int y) .(2分) int temp temp=*x;+x=*y;*y=temp;…(1分) 4.答:611(每个2分) 5.答 printf("num=号d, score=号f\n",tab1e1.num,tab1e1. score);(2分) printf("num=号d, score=号f\n",ptab->num,ptab-> score);…2分) 完成下列程序缺少部分(每空2分,只写出正确答案的一部分,可适当给 1分) 1 str[j-1 x[i] lp str[i] 4.x+b[k] 5. pname 三.编程题(10分) #include

答案: 一. 简答题(共 5 题,每题 4 分,共 20 分) 1. (x%5==0)&&(x%7!=0)或 x%5==0&&x%7!=0 或 !(x%5)&&x%7 (全对 4 分,否则按上面给分) 2. 答: int i,j; int max; max=a[0][0]; for(i=0;imax) ………………………………(1 分) max=a[i][j]; …………………………………(1 分) } 3. 答: 不能。…………………………………………………………………………(1 分) void swap(int * x,int * y)…………………(2 分) { int temp; temp = *x; *x = *y; *y = temp;…(1 分) } 4. 答:6 11 (每个 2 分) 5. 答: printf(”num=%d,score=%f\n”,table1.num,table1.score);(2 分) printf(”num=%d,score=%f\n”,ptab->num,ptab->score);……(2 分) 二. 完成下列程序缺少部分(每空 2 分,只写出正确答案的一部分,可适当给 1 分) 1. j-1 str[j-1] 2. p=j x[i][p] 3. str[i] i 4. r+b[k] *x 5. pname 三. 编程题(10 分) #include 1 分 1 分 1 分

char text[l= ["The programming language c was originally developed by Dennis Ritchie of Bell Laboratories and was designed to run on a PDP-11 with a UNIX operating system.) main()… .(1分) int i,j, upp, low, digit, space, otheri upp=low=digit=space=other=0 for(i=0;1=A′&&text[i][j]=a'&& text[i][j]=0′text[i][j]<=9′)…(1分) digit++ else if(text[i][j] (1分) space++ (1分) other++ printf(upper case: 8d\n", upp) printf("lower case: 8d\n", low)i printf(" digit:岩d、n", digit) printf("space: &d\n", space) printf(other: d\n",other (1分

char * text[]= {”The programming language C was originally developed ”, ”by Dennis Ritchie of Bell Laboratories and was designed ”, ”to run on a PDP-11 with a UNIX operating system.”}; main()……………………………………………………………………………………………………………………(1 分) { int i,j,upp,low,digit,space,other; upp=low=digit=space=other=0; for(i=0;i=’A’ && text[i][j]=’a’ && text[i][j]=’0’ && text[i][j]<=’9’)…(1 分) digit++; else if(text[i][j]==’ ’)……………………………………………………(1 分) space++; else…………………………………………………………………………………………………………(1 分) other++; } printf(”upper case: %d\n”,upp); printf(”lower case: %d\n”,low); printf(”digit: %d\n”,digit); printf(”space: %d\n”,space); printf(”other: %d\n”,other);…………………………………………………(1 分) }

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有