Part2 : 按要求写出符合要求的表达式,补全程序。 给出补全后完整的程序源码及运行结果截图。
Test 1:判断其是奇数还是偶数
#include <stdio.h> #include<stdlib.h> int main() { int x; printf("please input:\n"); scanf("%d", &x); if (x % 2 == 0) printf("even"); else printf("odd"); system("pause"); return 0; }
Test 2 判断是否是工作日
#include <stdio.h> #include<stdlib.h> int main() { int days; printf("please input:\n"); scanf("%d", &days); if (days >= 1 && days <= 5) printf("workdays,fighting\n"); else if (days == 6 || days == 7) printf("weekend,relax~\n"); else printf("Oops,not in 1~7\n"); system("pause"); return 0; }
Test 3 小写字母转换为大写字母
#include <stdio.h> #include<stdlib.h> int main() { char ch; printf("please input:\n"); scanf_s("%c", &ch); if (ch >= ‘a‘&&ch <= ‘z‘) ch -= 32; printf("%c", ch); system("pause"); return 0; }
Part 3 编程练习
编写程序,实现把一个十进制两位数整数转换成二进制。十进制整数由键盘输入,转换后的二进制数据输出到显示器上。
#include <stdio.h> #include<stdlib.h> int main() { int n; int a[32]; scanf_s("%d", &n); int i = 0; while (n > 0) { a[i++] = n & 1; n = n >> 1; } while (i--) { printf("%d", a[i]); } printf("\n"); system("pause"); return 0; }
原文:https://www.cnblogs.com/faspk/p/11695418.html