标签:image 复习 罗马 代码 浮点 nbsp hello ble 字符
任务一:
#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; }
d=0,e=71,f=70 结果不一致
line6:a%b*c line7:a*c%b line8:c%b*a
结果不同的原因是是整型,把小数点省略掉
任务2
#include<stdio.h> int main() { int x = 1234; float f = 123.456; double m = 123.456; char ch = ‘a‘; char a[] = "Hello,world!"; int y = 3, z = 4; printf("%d %d\n", y, z); printf("y=%d,z=%d\n", y, z); printf("%8d,%2d\n", x, x); printf("%f,%8f,%8.1f,%0.2f,%.2e\n", f, f, f, f, f); printf("%1f\n", m); printf("%3c\n", ch); printf("%s\n%15s\n%10.5s\n%2.5s\n%.3s\n", a, a, a, a, a); return 0; }
printf输出,%d输出整型,%8d空八格再输出,%2d空两格再输出,%f输出浮点型,%8f空八格输出浮点型,%8.1f空八格输出第一个,%0.2f不空格输出前两个,%e表示指数型,%后面数字表示空几个在输出
任务三
#include<stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d%d%d", &a1, &a2, &a3); printf("%d,%d,%d\n", a1, a2, a3); scanf("%c%c%c", &c1, &c2, &c3); printf("%c%c%c\n", c1, c2, c3); scanf("%lf,%lf", &x, &y); printf("%lf,%lf\n", x, y); return 0; }
任务4
#include<stdio.h> int main() { char x; x = getchar(); if ("x<=‘9‘&&x>‘0‘") printf("%c是数字字符\n", x); else if ("x<=‘z‘&&x>=‘a‘||x>=‘A‘&&x<‘Z‘") printf("%c是英文字母\n", x); else printf("%c是其他字符\n", x); return 0; }
任务5
#include<stdio.h> int main() { char ans1, ans2; printf("复习了没?(输入y或Y表示复习了,输入n或N表示没复习):"); ans1 = getchar(); getchar(); printf("\n动手敲代码了没?(输入y或Y表示敲了,输入n或N表示木有敲):"); ans2 = getchar(); if ("ans1=y||ans1=Y") printf("\n罗马不是一天建成的:)\n"); else printf("\n罗马不是一天毁灭的。。。\n"); return 0; }
任务6
#include<stdio.h> #include<math.h> int main() { int n, q, sum; q = 2; scanf("%d", &n); sum = 1 * (1 - pow(q, n)) / (1 - q); printf("n=%d时,sum=%d", n, sum); return 0; }
标签:image 复习 罗马 代码 浮点 nbsp hello ble 字符
原文地址:https://www.cnblogs.com/7heng/p/13908421.html