6道上机题参考代码全部按照题目给定的提示字符串、格式串原样复制避免OJ判错1、日期显示#include stdio.h int main() { int mm, dd, yy; printf(Enter a date (mm/dd/yy):\n); scanf(%d/%d/%d, mm, dd, yy); printf(You entered the date: %04d.%02d.%02d\n, yy, mm, dd); return 0; }2、产品信息格式化#include stdio.h int main() { int item; float price; int mm, dd, yy; printf(Enter item number:\n); scanf(%d, item); printf(Enter unit price:\n); scanf(%f, price); printf(Enter purchase date (mm/dd/yy):\n); scanf(%d/%d/%d, mm, dd, yy); printf(Item Unit Purchase\n); printf(%-9d$ %-9.2f%02d%02d%04d\n, item, price, mm, dd, yy); return 0; }3、计算两个数的平方和#include stdio.h #include math.h int main() { float x, y, res; printf(Please input x and y:\n); scanf(%f,%f, x, y); res pow(x,2) pow(y,2); printf(Result%.2f\n, res); return 0; }4、逆序数的拆分计算#include stdio.h int main() { int x; int thousand, hundred, ten, one; int y, a, b, result; printf(Input x:\n); scanf(%d, x); // 取绝对值忽略正负 if(x 0) x -x; thousand x / 1000; hundred x / 100 % 10; ten x / 10 % 10; one x % 10; y one * 1000 ten * 100 hundred * 10 thousand; a y / 100; b y % 100; result a*a b*b; printf(y%d\n, y); printf(a%d,b%d\n, a, b); printf(result%d\n, result); return 0; }5、拆分英文名#include stdio.h int main() { char c1, c2, c3; printf(Input your English name:\n); scanf(%c%c%c, c1, c2, c3); //首字母大写小写字母 -32 c1 c1 - 32; printf(%c%c%c\n, c1, c2, c3); printf(%c:%d\n, c132, c1 - a 1); printf(%c:%d\n, c2, c2 - a 1); printf(%c:%d\n, c3, c3 - a 1); return 0; }6、计算体指数#include stdio.h int main() { int weight_kg, height_cm; float w_jin, h_m, t; printf(Input weight, height:\n); scanf(%d,%d, weight_kg, height_cm); w_jin weight_kg * 2; h_m height_cm / 100.0; t weight_kg / (h_m * h_m); printf(weight%d\n, (int)w_jin); printf(height%.2f\n, h_m); printf(t%.2f\n, t); return 0; }
阅读完成 · 觉得有帮助?