2017年9月18日 星期一

[C_MM28-易] 計算1到N之間屬於5和7的倍數(C++)

[C_MM28-易] 計算1到N之間屬於5和7的倍數

  1. #include <iostream>  
  2. using namespace std;  
  3.   
  4. int main() {  
  5.     int num;  
  6.     while(cin >> num)  
  7.     {  
  8.         for(int i = 1;i <= num;i++)  
  9.         {  
  10.             if(i % 35 == 0)  
  11.             {  
  12.                 if(num - i < 35)  
  13.                 {  
  14.                     cout << i;  
  15.                 }  
  16.                 else  
  17.                 {  
  18.                     cout << i << " ";  
  19.                 }  
  20.             }  
  21.         }  
  22.         cout << "" << endl;  
  23.     }  
  24.     return 0;  
  25. }  


沒有留言:

張貼留言