Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ZADANIE 1
- function WARTOŚĆ_BEZWZGLĘDNA (x){
- if(x<0){
- return x*-1;
- }
- else{
- return x;
- }
- }
- document.write(WARTOŚĆ_BEZWZGLĘDNA(12)+"<br>");
- document.write(WARTOŚĆ_BEZWZGLĘDNA(-14));
- //Zadanie 2
- function CZY_PARZYSTA (x){
- if(x%2==0){
- document.write ("TRUE"+"<br>");
- }
- else{
- document.write ("FALSE"+"<br>");
- }
- }
- CZY_PARZYSTA(12);
- CZY_PARZYSTA(3);
- //ZADANIE 3
- function SZLACZEK (x,y){
- for(var i=0;i<=y;i++){
- document.write(x);
- }
- }
- SZLACZEK("#",5)
- //ZADANIE 4
- var ilosc = Number (prompt("Podaj ilocyfrowe liczby Cię interesują: "));
- var dzielnik = Number (prompt("Podaj przez co mają być podzielne: "));
- PODZIELNOSC(ilosc,dzielnik)
- function PODZIELNOSC (x,y){
- var max=10**x;
- var min=10**(x-1);
- document.write("Twoje liczby to: ");
- for(var i=min;i<=max;i++){
- if(i%y==0){
- document.write(i+", ")
- }
- }
- }
- //ZADANIE 5
- function OBWOD_TROJKATA (x,y,z){
- if(x+y<=z && x+z<=y && z+y<=x){
- return -1;
- }
- else{
- return (x+y+z);
- }
- }
- var x = OBWOD_TROJKATA(3,4,5);
- if (x===-1){document.write("Nie da się utworzyć trójkąta");}
- else{document.write("Da się utworzyć trójkąt o obwodzie: "+x);}
- //ZADANIE 6
- function SILNIA(x){
- if(x<=1){
- return 1;
- }
- else{
- return x*SILNIA(x-1);
- }
- }
- document.write(SILNIA(5));
- //ZADANIE 7
- function LICZBA_PIERWSZA (x){
- var i=2;
- for(i;i<=x;i++){
- if(x%i==0){
- return 0;
- }
- else if(i==x-1){
- return 1;
- }
- }
- }
- var x = LICZBA_PIERWSZA(8);
- if(x===1){document.write("Podana liczba jest liczbą pierwszą"+"</br>");}
- else
- {document.write("Podana liczba nie jest liczbą pierwszą"+"</br>");}
- //ZADANIE 8
- function LICZBA_CYFR (x){
- a=x;
- for(i=0;x>=1;i++){
- x=x/10;
- }
- document.write("Ilość cyfr w liczbie "+a+" wynosi: "+i);
- }
- LICZBA_CYFR(301939);
- document.write("<br>");
- LICZBA_CYFR(420);
- document.write("<br>");
- LICZBA_CYFR(7532222222);
- //ZADANIE 9
- function LICZBA_CYFR (x){
- var sum=0;
- var a=0;
- while(x>=1){
- a=x%10;
- x=(x-a)/10;
- sum=sum+a;
- }
- if(sum>10){
- LICZBA_CYFR(sum);
- }
- else{
- document.write(sum);
- }
- }
- LICZBA_CYFR(301939);
- document.write("<br>");
- //ZADANIE 10
- function FIBONACCI (x){
- if(x<=2){
- return 1;
- }
- else{
- return FIBONACCI(x-1)+FIBONACCI(x-2);
- }
- }
- document.write(FIBONACCI(7));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement