Advertisement
3vo

Problem 1. Numbers from 1 to N

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