Advertisement
PiotrTwardowski

Funkcje JS Piotr Twardowski 4bTI/2 nr.27

Jan 20th, 2022
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // z.1
  2.  
  3. const prompt=require('prompt-sync')();
  4.  
  5. function bezw(x)
  6. {
  7.     if(x>0)
  8.     {
  9.         return x;
  10.     }
  11.     else if(x<0)
  12.     {
  13.         return (-x);
  14.     }
  15. }
  16. const x= +prompt ("Podaj liczbe: ");
  17. console.log(bezw(x));
  18.  
  19.  
  20. // z.2
  21.  
  22.  
  23. const prompt=require('prompt-sync')();
  24.  
  25.  
  26. function parzysta(x)
  27. {
  28. if (x%2==0)
  29. {
  30.     return true;
  31. }
  32. else
  33. {
  34.     return false;
  35. }
  36. }
  37.  
  38.  
  39. const x= +prompt ("Podaj liczbe: ");
  40. console.log(parzysta(x));
  41.  
  42.  
  43. // z.3
  44.  
  45.  
  46. const prompt=require('prompt-sync')();
  47.  
  48.  
  49. function podzielnosc(x,y)
  50. {
  51.     let z=1;
  52.     for (let i= 0;i<x-1;i++)
  53.     {  
  54.         z*=10;
  55.     }
  56.     for (let i=z;i<z*10-1;i++)
  57.     {
  58.         if(i%y==0)
  59.         {
  60.             console.log(i);
  61.         }
  62.     }
  63. }
  64.  
  65.  
  66. const x= +prompt ("Podaj ilocyfrowe liczby: ");
  67. const y= +prompt ("Podaj dzielnik: ");
  68. console.log(podzielnosc(x,y));
  69.  
  70.  
  71.  
  72. // z.4
  73.  
  74.  
  75. const prompt=require('prompt-sync')();
  76.  
  77.  
  78. function pierwsza(x)
  79. {
  80.     if(x>=2)
  81.     {
  82.         for(let i=2;i*i<=x;i++)
  83.         if(x%i==0)
  84.         {
  85.             return 0;
  86.         }
  87.         return 1;
  88.     }
  89.     else
  90.     {
  91.         return 0;
  92.     }
  93. }
  94.  
  95.  
  96. const x= +prompt ("Podaj liczbe: ");
  97. if(pierwsza(x)==1)
  98. {
  99.     console.log("Liczba pierwsza")
  100. }
  101. else if(pierwsza(x)==0)
  102. {
  103.     console.log("Nie liczba pierwsza")
  104. }
  105.  
  106.  
  107. // z.5
  108.  
  109.  
  110. const prompt=require('prompt-sync')();
  111.  
  112.  
  113. function liczbacyfr(x)
  114. {
  115.  x= x.toString();
  116.  let i=0;
  117.  i= x.length;
  118.  return i;
  119. }
  120.  
  121. const x= +prompt ("Podaj liczbe: ");
  122. console.log(liczbacyfr(x));
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement