电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C语言实验答案重庆大学出版社(杨永斌丁明勇)

C语言实验答案重庆大学出版社(杨永斌丁明勇)_第1页
1/43
C语言实验答案重庆大学出版社(杨永斌丁明勇)_第2页
2/43
C语言实验答案重庆大学出版社(杨永斌丁明勇)_第3页
3/43
一 2、①a/b ②a%b 3.(1) #include "stdio.h" #include "conio.h" void main() { float r,s; r=10; s=3.14*r*r; printf("s=%.4f\n\n",s); getch(); } (2) #include "stdio.h" #include "conio.h" #include void main() { int s,num1,num2,num=100; /*初始化随机数发生器,其作用是每次运行程序时使 rand()产生的随机数不一样*/ int rand(); num1=rand()%num +1; /*产生 num 范围内的随机加法数1*/ num2=rand()%num +1; /*产生 num 范围内的随机加法数2*/ printf("%d + %d = ",num1,num2); printf("请输入你的答案: "); scanf("%d",&s); if(num1+num2==s) /*判断是否答对*/ printf("Yes,你答对了。%c\n",7); /*7为响铃*/ else /*答错的处理*/ printf("No,你答错了。\n"); getch(); } 二 1.验证性实验 (1) 程序运行结果 x=10,y=10,z=10 x=8,y=10,z=16 c1=M,c2=4d,c3=115,c4=77 c1=M,c2=M,c3=M,c4=M c1=77,c2=77,c3=77,c4=77 c=m,c=109 (2)程序运行结果 输入: 1,2 3,4 5,6 7,6 a,b 输出: a= 1,b= 2 c= 3.00,d= 4.00 e= 5,f= 6 u=7,v=6 c1= ,c2=2 输入: 1,2 2,3 3,4 4,5a,b 输出: a= 1,b= 2 c= 2.00,d= 3.00 e= 3,f= 4 u=4,v=5 c1=a,c2=b (3)程序运行结果 12345678123456781234567812345678 5 6 7 5 6 7 c:\a.txt 2. 填空性实验 ①%f ②&h ③pi*r*r ④s*h ⑤v 3.程序改错 (1) #include "stdio.h" #include "conio.h" void main() { float a,b,x; a=3.1; b=4.5; x=a+b; printf("%.0f",x); getch(); } (2) #include "stdio.h" #include "conio.h" void main() { int x,a; x=12345; a=x%10; printf("%d",a); getch(); } 4.设计性实验 (1) #include "stdio.h" #include "conio.h" void main() { float x,y,z; printf("Please input 2 reals"); scanf("%f%f",&x,&y); z=x;x=y;y=z; printf("After swapped,x=%f,y=%f",x,y); getch(); } (2) #include "stdio.h" #include "conio.h" void main() { char a,b; a=127; b=a+1; printf("a=%c,a+1=%c\n",a,b); printf("a=%d,a+1=%d\n",a,b); a=-128; b=a-1; printf("a=%c,a-1=%c\n",a,b); printf("a=%d,a+1=%d\n",a,b); getch(); } 三 一、验证性试验: 由于程序主函数结尾缺少"getc...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C语言实验答案重庆大学出版社(杨永斌丁明勇)

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部