1.spa
1 #include <stdio.h> 2 #define MINU 60 3 4 int main() 5 { 6 int minute, hour, m; 7 printf("請輸入分鐘:"); 8 while(scanf("%d", &m)) //若是輸入的不是數字,則會退出 9 { 10 hour = m / MINU; 11 minute = m % MINU; 12 printf("轉化爲%d 小時 %d 分鐘\n", hour, minute); 13 } 14 printf("退出\n"); 15 getchar(); 16 return 0; 17 }
2.code
1 #include <stdio.h> 2 #define STEP 10 3 4 int main() 5 { 6 int num, tmp; 7 printf("請輸入一個整數:"); 8 while(scanf("%d", &num)) 9 { 10 tmp = num + 10; 11 while(num <= tmp){ 12 printf("%d ", num); 13 num += 1; 14 } 15 printf("\n"); 16 printf("請輸入一個整數:"); 17 } 18 printf("退出\n"); 19 getchar(); 20 return 0; 21 }
2.第二題的do while 方式 blog
1 #include <stdio.h> 2 #define STEP 10 3 4 int main() 5 { 6 int num, tmp, status; 7 do 8 { 9 printf("請輸入一個整數:"); 10 status = scanf("%d", &num); 11 tmp = num + 10; 12 while(num <= tmp){ 13 printf("%d ", num); 14 num += 1; 15 } 16 printf("\n"); 17 }while(status==1); //status 標識輸入的是不是規範數字 18 printf("退出\n"); 19 getchar(); 20 return 0; 21 }