Advertisement
3vo

Problem 2. Numbers Not Divisible by 3 and 7

3vo
Nov 2nd, 2022
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Problem 2. Numbers Not Divisible by 3 and 7
  2. //
  3. // Write a program that enters from the console a positive integer n
  4. // and prints all the numbers from 1 to n not divisible by 3 or 7,
  5. // on a single line, separated by a space.
  6. //
  7.  
  8. //     Examples:
  9. // n    output
  10. // 3    1 2
  11. // 10   1 2 4 5 8 10
  12. let input = ['10'];
  13. let print = this.print || console.log;
  14. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  15.  
  16. let num = Number(gets());
  17. let result = '';
  18.  
  19. for (let i = 1; i <= num; i++) {
  20.  
  21.     if (i % 3 === 0 || i % 7 === 0) {
  22.         continue;
  23.     }
  24.     result = result + i + ' ';
  25. }
  26. console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement