C語言學習 18-9-20
阿新 • • 發佈:2018-12-06
練習題
-
水仙花數
水仙花數是指三位數,這三位數滿足:個位2 + 十位2 + 百位**2 = 這個三位數本身。#include<stdio.h> int main() { int num = 100; int the_uint, the_decade, the_hundred; for(num; num<1000; num++) { the_hundred = num/100; the_decade = (num - the_hundred * 100)/10; the_uint = num%10; if(the_uint*the_uint + the_decade*the_decade + the_hundred*the_hundred == num) { printf("水仙花數:%d\n", num); } } return 0; }
-
99乘法表
#include<stdio.h> int main() { int mul1, mul2; for(mul1=1; mul1<10; mul1++) { for(mul2=1; mul2<=mul1; mul2++) { printf("%d*%d=%d\t", mul1, mul2, mul1*mul2); } printf("\n"); } return 0; }