avr39-ripe

defectiveNum

Jun 13th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. int main() {
  5.     int number=0;
  6.     int digitsNum=0;
  7.     int totalDefective=0;
  8.  
  9.     while (number++ < 50000)
  10.     {
  11.         digitsNum=number;
  12.         while ( digitsNum > 0)
  13.         {
  14.             if (digitsNum%10 == 2)
  15.             {
  16.                 std::cout<<"number= "<<number<<endl;
  17.                 totalDefective++;
  18.                 break;
  19.             }
  20.             digitsNum/=10;
  21.         }
  22.     }
  23.  
  24.     std::cout<<"totalDefective="<<totalDefective<<endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment