Advertisement
3vo

Circle Perimeter and Area

3vo
Feb 8th, 2023 (edited)
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.96 KB | Source Code | 0 0
  1. /*
  2. Circle Perimeter and Area
  3. Write a program that reads the radius r of a circle and prints its perimeter and
  4. area formatted with 2 digits after the decimal point.
  5.  
  6.  
  7. Examples:
  8. r           perimeter           area
  9. 2           12.57               12.57
  10. 3.5         21.99               38.48
  11. */
  12.  
  13. // Vladi code
  14. function solve(input){
  15.  
  16.     // radius
  17.     let pr = +input[0];
  18.     let radius = Math.PI * pr * pr;
  19.  
  20.     console.log(radius.toFixed(2));
  21.  
  22.     // perimeter
  23.  
  24.     let perimeter = Math.PI * 2 * pr;
  25.  
  26.     console.log(perimeter.toFixed(2));
  27.  
  28. }
  29.  
  30. solve(['2'])
  31. //----------------------------
  32. // Evo code
  33. //get data from judge-a тук
  34. let input = [
  35.     '3.5'
  36. ];
  37.  
  38. let print = this.print || console.log;
  39. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  40. // до тук бат Влади
  41. let radius = Number(gets());
  42.  
  43. let perimeter = (2 * Math.PI * radius).toFixed(2);
  44. let area = (Math.PI * (Math.pow(radius, 2))).toFixed(2);
  45. print(perimeter);
  46. print(area);
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement