《C语言程序设计实验与习题》上机实

上传人:woxinch****an2018 文档编号:39309985 上传时间:2018-05-14 格式:DOC 页数:29 大小:216.50KB
返回 下载 相关 举报
《C语言程序设计实验与习题》上机实_第1页
第1页 / 共29页
《C语言程序设计实验与习题》上机实_第2页
第2页 / 共29页
《C语言程序设计实验与习题》上机实_第3页
第3页 / 共29页
《C语言程序设计实验与习题》上机实_第4页
第4页 / 共29页
《C语言程序设计实验与习题》上机实_第5页
第5页 / 共29页
点击查看更多>>
资源描述

《《C语言程序设计实验与习题》上机实》由会员分享,可在线阅读,更多相关《《C语言程序设计实验与习题》上机实(29页珍藏版)》请在金锄头文库上搜索。

1、CC 语言程序设计实验与习题语言程序设计实验与习题 上机实验参考答案上机实验参考答案(此答案仅作为教师指导学生上机实验时参考使用,不得转发给学生!)(此答案仅作为教师指导学生上机实验时参考使用,不得转发给学生!)第第 2 章章实验一实验一 基本数据类型基本数据类型1、float c;double d;c=211.5f; d=211.5;printf(“a/b=%dn“,a/b);2、printf(“%d,%o,%xn“,0x65,0x65,0x65);3、e=o+2;f=m+2;g=e+2;4、ra=de*PI/180;实验二实验二 算术运算符和表达式算术运算符和表达式1、printf(“%f

2、n“,x+a%3*(int)(x+y)%2/4);printf(“%fn“,(float)(a+b)/2+(int)x%(int)y);2、printf(“%dn“,(x=1,y=100,z=(x+y)*5);printf(“%dn“,x=(i=10,j=5,i*j);printf(“%dn“,(x=i=10,j=5,i*j);3、 double a,b,c,s,area;area=sqrt(s*(s-a)*(s-b)*(s-c);第第 3 章章实验一实验一 数据的格式化输出数据的格式化输出略实验二实验二 数据的格式化输入数据的格式化输入1、 a=b;B=g;2、1012410.343、 a=

3、3b=7x=8.57y=71.82c1=Ac2=a4、略第第 4 章章实验一实验一 ifif 语句语句2、wan=ge printf(“输入 x,y 的值: n“); scanf(“%f%f“, if ( x = 0else if ( x = 0 ) z = sin(x)+cos(y);else if ( x void main()float m,y,s;printf(“请输入本金和存款年限:n”);scanf(“%f%f“,if(y8) n=y-8; y=8;switch(y)case 1: s = m + m * 0.63% * 12; break;case 2: s = m + m *

4、0.66% * 12 * 2; break;case 3: case 4: s = m + m * 0.69% * 12 * y; break;case 5: case 6: case 7: s = m + m * 0.75% * 12 * y; break;case 8: s = m + m * 0.84% * (y+n); break;defaut:printf(“wrongn“);printf(“本金利息合计: %fn”,s);第第 5 章章实验一实验一 循环语句的使用循环语句的使用1、temp =m;m=n;n=temp; m=n;n=r2、tn=tn+a; a=a*10;3、 【程序

5、如下:】#include void main()float s,f0,h,x;int n,i;printf(“输入区间分隔数 n:”);scanf(“%d”,h=1.0/n;f0=4.0; /初值,x=0.0 时 f(0.0)=4.0s=0.0;for(i=1;i#include void main() long int sum,temp;int n,i,j=1;printf(“Please input how many terms you want the computer to calculate(19):n”);scanf(“%d”,if(n=10) printf(“Overflow !

6、n”);exit(0);sum=0;for(i=1;i=4)3、 【程序如下:】#include void main()int m,i,s;for ( m=2;mvoid main() int x,y,z;for(x=0;xaj+1)temp=aj;aj=aj+1;aj+1=temp;3、scanf(“%d“,for(i=0;n!=0;i+)numi=n%base;n=n/base;printf(“the result is:“);for(i-;i=0;i-)if(numi=0high=i; else if(sumi4) printf(“请重新输入:n“);scanf(“%d“,for(j=1

7、;j6) printf(“请重新输入:n“);scanf(“%d“,aver0=0;for(i=1;i=a *n=*p2; else *m=*p2; *n=*p1;if(*m*p3) *n=*p3;3、switch(c) case u: *(unsigned *)p3)=*(unsigned *)p1); *(unsigned *)p1)=*(unsigned *)p2); *(unsigned *)p2)=*(unsigned *)p3);break;case i: *(int *)p3)=*(int *)p1); *(int *)p1)=*(int *)p2); *(int *)p2)=*

8、(int *)p3);break;case f: *(float *)p3)=*(float *)p1); *(float *)p1)=*(float *)p2); *(float *)p2)=*(float *)p3);break;case d: *(double *)p3)=*(double *)p1); *(double *)p1)=*(double *)p2); *(double *)p2)=*(double *)p3);break;case c: *(char *)p3)=*(char *)p1); *(char *)p1)=*(char *)p2); *(char *)p2)=*(

9、char *)p3);实验二实验二 指针与数组指针与数组1、while(p=a;p-) *(p+1)=*p; *a=t; count+; 实验三实验三 指针数组与指向指针的指针指针数组与指向指针的指针1、for(i=1;i*p0) p0= elsefor(m=4;m=1;m-)if(aij*(a+*p) *p=i; return a+*p;第第 9 章章实验一实验一 字符数组字符数组1、for(j=0;j=A for(j=1;sj!=0;j+) sj-1=sj; i-; sj-1=0;3、for(len=0;silen!=0;len+); half=len/2; for(j=0;jsik) c

10、h=sij; sij=sik; sik=ch; 实验二实验二 字符串指针变量字符串指针变量1、for(p=str;*p!=0;p+) if(*p= ) word=0; else if(word=0)word=1; if(*p=a float price; ; void sort(struct Book b, int n);void main( ) struct Book bN; int i;printf(“Please input %d books information as follow: n“, N); printf(“Name Pricen“); for (i = 0; i bj+1.

11、price) k = bj; bj = bj+1; bj+1 = k; 实验二实验二 共用体共用体1、 The size of int is 4. The size of char is 1. The size of float is 4. The size of union U_value is 4. The size of u1 is 4. The value of u1.iv is 100 The value of u1.cv is d The value of u1.fv is 0.000000 The size of u2 is 4. The value of u2.iv is -8

12、58993599 The value of u2.cv is A The value of u2.fv is -107373064.000000 The size of u3 is 4. The value of u3.iv is 1078523331 The value of u3.cv is ? The value of u3.fv is 3.1400002、 #include #define N 10 union Category long stu_class; char tea_position20; ; struct Person long id; char name16; char

13、 sex; int age; char flag; union Category cp; ;void main( ) struct Person stN; int i;printf(“Please input %d persons information as follow: n“, N); printf(“Id Name Sex Age Flag n“); for (i = 0; i 20) printf(“%-10ld%-17s%-4c%-4d%-5c%-22ldn“, sti.id, sti.name, sti.sex, sti.age, sti.flag, sti.cp.stu_cla

14、ss); else if (sti.flag = T ptr = tail; printf(“nplease input 5 data:n“); for(i = 0; i data = num; head = (struct list *)malloc(sizeof(struct list); head-next = ptr; ptr = head; ptr = ptr-next; while(ptr != NULL) printf(“The value is: %dn“, ptr-data); ptr = ptr-next; 实验四实验四 枚举枚举1、 if (i != j) show(j)

15、; show(k); printf(“n“); 第第 11 章章实验一实验一 宏定义和文件包含宏定义和文件包含1、略2、略3、(1)ex1101.h#define f1(a, b) a*b#define f2(c, d) (c)*(d)#define f3(x, y, z) (z=x, x=y, y=z)(2)#include #include “ex1101.h“void main()int a, b, c;double f, g, h;scanf(“%d%d“, scanf(“%lf%lf“, f3(a, b , c);f3(f, g, h);printf(“a=%d, b=%dn“, a, b);printf(“f=%f, g=%fn“, f, g);实验二实验二 条件编译条件编译1、略2、略3、#include #define UPPERCASE#define ISLOWER(c) (c=aint i, key;printf(“请输入一个字符串:n“);gets(s

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号