实验一
#include <stdio.h> int main() { printf("201883300094"); return 0; }
一part 1
1. 将"hello,world!"改为学号后运行,需要谨记住分号和双引号,最开始学时很容易忘记。
2.输入教材p3的程序
int main(void) { int x ,y ,s; scanf("%d%d,&x,&y"); s=product(x,y); printf("The mul is %d",s); return 0; } int product (int a ,int b) { int mul; mul=a*b; return mul; }
为了计算乘积,定义一个子函数product ,再调用定义的mul的值来表达结果。目前对我来说= =嗯主要就是看书不要输错了,理解大概吧
3.p116 实验(1)
#include <stdio.h> int main() { int a=5,b=7,c=100 ,d,e,f; d=a/b*c; e=a*c/b; f=c/b*a; printf("d=%d,e=%d,f=%d\n",d,e,f); return 0; }

运行结果如图,根据c语言算术运算符的优先级顺序就是这样的结果了。(算术运算符内容p23)
(2)自加自减运算
#include <stdio.h> int main() { int a=5,b=8; printf("a++=%d\n",a++) ; printf("a=%d\n",a); printf("++b=%d\n",++b); printf("b=%d\n",b); return 0; }

(道路千万条,规范第一条,码字听音乐,代码错n行。)这条代码修改了无数次因为音乐太好听赋值全部串行了= =
此题是考察前置运算和后置运算。
(3)关系运算和逻辑运算
#include <stdio.h> int main() { int a=5,b=8,c=8; printf("%d,%d,%d,%d\n",a==b&&a==c,a!=b&&a!=c,a>=b&&a>=c,a<=b&&a<=c); printf("%d,%d\n",a<=b||a>=c,a==b||b==c); printf("%d,%d,%d\n",!(a==b),!(a>=b),!(a>=c),!(a<=b)); return 0; }
考点大概是逻辑判断真or假,顺便对逻辑运算符的考察。
part2
(1)判断奇偶
#include <stdio.h> int main()
{ int x; printf("please input a number : \n"); scanf("%d",&x); if(x%2!=0) printf("是奇数"); else printf("是偶数"); return 0; }
运行结果如图
(2)
#include <stdio.h> int main() { int days; printf("please input a number: \n"); scanf("%d",&days); if(days<=5&&days>=1) printf("workdays,fighting \n"); else if (days==6||days==7) printf("weekend,relax~\n"); else printf("oppos,not in 1~7 \n"); return 0; }


此题篇幅比较长,因为我犯了一个错误,找了很久都没有找到= =问了好几个人总算有大佬指出了我的错误。
因为没有用模板直接自己打,所以如图"%d,&days",将取地址也放到了引号中,导致运行的结果一直为错误。
(3)
#include<stdio.h> int main(void) { char ch; printf("输入一个字符:\n"); scanf("%c",&ch); if(ch>='a'&&ch<='z') ch=ch-32; printf("%c\n",ch); return 0; }


浙公网安备 33010602011771号