1.年月日转换 #include<stdio.h> int main() { int yyyy, mm, dd; printf("Enter a date(mm/dd/yyyy):"); scanf("%d/%d/%d", &mm, &dd, &yyyy); printf("you enter the date %.4d%.2d%.2d", yyyy, mm, dd); return 0; } 2.格式化 #include<stdio.h> int main() { int sm,mm, dd,yyyy; float price; printf("Enter item number:\n"); scanf("%d", &sm); printf("Enter unit price:\n"); scanf("%f", &price); printf("Enter purchase date(yyyy,mm,dd)"); scanf("%d/%d/%d",&yyyy,&mm,&dd); printf("Item\tUnitprice\tPurchase date\n"); printf("%d\t$%4.2f\t\t%d/%.2d/%.2d", sm, price, yyyy, mm, dd); return 0; } 3.ISBN #include<stdio.h> int main() { int aaa, b, ccc, ddddd, e; printf("Enter ISBN:\n"); scanf("%d-%d-%d-%d-%d", &aaa, &b, &ccc, &ddddd, &e); printf("GSI Prefix:%.3d\n",aaa); printf("Group identifiier:%d\n",b); printf("Publisher code:%.3d\n",ccc); printf("Item number:%.5d\n",ddddd); printf("Check digit:%d\n",e); return 0; } 4.电话号码 #include<stdio.h> int main() { int aaa, bbb, cccc; printf("Enter phone number[(xxx) xxx-xxxx]:\n"); scanf("(%d)%d-%d", &aaa, &bbb, &cccc); printf("You entered %.3d.%.3d.%.4d\n", aaa, bbb, cccc); return 0; } 5.6.行列角sum #include<stdio.h> int main() { int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, rs1, rs2, rs3, rs4, cs1, cs2, cs3, cs4, ds1, ds2; printf("Enter the number from 1 to 16 in any order\n"); scanf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p); printf("%d\t%d\t%d\t%d\n", a, b, c, d); printf("%d\t%d\t%d\t%d\n", e, f, g, h); printf("%d\t%d\t%d\t%d\n", i, j, k, l); printf("%d\t%d\t%d\t%d\n", m, n, o, p); rs1 = a + b + c + d; rs2 = e + f + g + h; rs3 = i + j + k + l; rs4 = m + n + o + p; cs1 = a + e + i + m; cs2 = b + f + j + n; cs3 = c + g + k + o; cs4 = d + h + l + p; ds1 = a + f + k + l; ds2 = d + g + j + m; printf("Row sums:%d\t%d\t%d\t%d\n", rs1, rs2, rs3, rs4); printf("Colum sums:%d\t%d\t%d\t%d\n", cs1, cs2, cs3, cs4); printf("Diagonal sums:%d\t%d", ds1, ds2); return 0; } 7.数字逆转 #include<stdio.h> int main() { int number; printf("请输入一个三位数字:\n"); scanf("%d", &number); number = (number % 100) % 10 * 100 + number / 100 + (number % 100) / 10 * 10; printf("逆转的数字为:%d", number); return 0; } 8.八进制转换 #include<stadio.h> int main() { int a,b,c,d,e,f; printf("Enter a number between 0 and 32767:"); scanf("%d",&a); b=a%8; c=a/8%8; d=a/8/8%8; e=a/8/8/8%8; f=a/8/8/8/8%8; h=a+10b+100c+1000d+10000f; printf("In octal,your number is%d",h); return 0; } 9.校验位 #include<stdio.h> int main() { int c, a1, a2, a3, a4, a5, b1, b2, b3, b4, b5, sum1,sum2,sum; printf("Enter the first (single) digit:\n "); scanf("%d", &c); printf("Enter the first group of five digit:\n"); scanf("%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5); printf("Enter the next group of five digit:\n"); scanf("%1d%1d%1d%1d%1d", &b1, &b2, &b3, &b4, &b5); sum1 = c + a2 + a4 + b1 + b3 + b5; sum2 = a1 + a3 + a5 + b2 + b4; sum = 9-(sum1 * 3 + sum2 - 1) % 10; printf("Check digit:%d\n", sum); return 0; } 10.upc #include<stdio.h> int main() { unsigned long long int number; int sum1, sum2, a, cd; printf("Enter the first 12 digits of EAN:"); scanf("%d", &number); sum1 = (number % 100000000000) + (number % 1000000000 / 100) + (number % 10000000 / 10000) + (number % 100000 / 1000000) + (number % 1000 / 100000000) + (number % 10 / 10000000000); sum2 = (number % 10000000000 / 10) + (number % 100000000 / 1000) + (number % 1000000 / 100000) + (number % 10000 / 10000000) + (number % 100 / 1000000000) + (number / 100000000000); a = (sum1 * 3 + sum2 - 1) % 10; cd = 9 - a; printf("Check digit:%d", cd); return 0; }
来源:oschina
链接:https://my.oschina.net/u/4760285/blog/4708272