Advertisement
rikardoricz

Tomasz Świątek 3bti/2 petle

Dec 9th, 2020 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.18 KB | None | 0 0
  1. //Zadanie 1
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int x,y,z;
  9.  
  10.     for (x=1;x<=100;x++)
  11.     {
  12.         cout << x << endl;
  13.     }
  14.  
  15.     y=1;
  16.     do
  17.     {
  18.         cout << y << endl;
  19.         y++;
  20.     }
  21.     while (y<=100);
  22.  
  23.     z=1;
  24.     while(z<=100)
  25.     {
  26.         cout << z << endl;
  27.         z++;
  28.     }
  29.  
  30.     return 0;
  31. }
  32.  
  33. //Zadanie 2
  34. #include <iostream>
  35.  
  36. using namespace std;
  37.  
  38. int main()
  39. {
  40.     int a,b,i,x;
  41.     cout << "Podaj krance przedzielu [a,b]: " << endl;
  42.     cin >> a >> b;
  43.  
  44.     if (b<a)
  45.     {
  46.         x=a;
  47.         a=b;
  48.         b=x;
  49.     }
  50.  
  51.     for (i=a; i<=b; i++)
  52.     {
  53.         if (i%3==0)
  54.         {
  55.             cout << "Liczba " << i << " jest podzielna przez 3" << endl;
  56.         }
  57.         else
  58.         {
  59.             cout << "Liczba " << i << " nie jest podzielna przez 3" << endl;
  60.         }
  61.     }
  62.     return 0;
  63. }
  64.  
  65. //Zadanie 3
  66. #include <iostream>
  67.  
  68. using namespace std;
  69.  
  70. int main()
  71. {
  72.     int x,s;
  73.     s=1;
  74.  
  75.     cout << "Podaj liczbe, z ktorej ma byc obliczona slinia: ";
  76.     cin >> x;
  77.  
  78.     if (x<0)
  79.     {
  80.         cout << "Podana liczba < 0, program zakonczy dzialanie";
  81.         return 0;
  82.     }
  83.     else if (x==0)
  84.     {
  85.         cout << "0!=1";
  86.     }
  87.     else
  88.     {
  89.         for (int i=1;i<=x;i++)
  90.         {
  91.             s=s*i;
  92.         }
  93.         cout << s;
  94.     }
  95.     return 0;
  96. }
  97.  
  98.  
  99. //Zadanie 4
  100. #include <iostream>
  101.  
  102. using namespace std;
  103.  
  104. int main()
  105. {
  106.     int x;
  107.  
  108.     for (x=10;x<100;x++)
  109.     {
  110.         if (x%4==0)
  111.         {
  112.             cout << x << endl;
  113.         }
  114.     }
  115.  
  116.     return 0;
  117. }
  118.  
  119. //Zadanie 5
  120. #include <iostream>
  121.  
  122. using namespace std;
  123.  
  124. int main()
  125. {
  126.     int k,x;
  127.     cout << "Podaj krok: ";
  128.     cin >> k;
  129.  
  130.     cout << "krok = " << k << " -> ";
  131.  
  132.     for (x=0;x<=200;x=x+k)
  133.     {
  134.         cout << " " << x;
  135.     }
  136.     return 0;
  137. }
  138.  
  139. //Zadanie 6
  140. #include <iostream>
  141.  
  142. using namespace std;
  143.  
  144. int main()
  145. {
  146.     int i,x,s;
  147.     i=1;
  148.     s=0;
  149.  
  150.     while (i<=10)
  151.     {
  152.         cout << "Podaj " << i << " liczbe: ";
  153.         cin >> x;
  154.         s=s+x;
  155.         i++;
  156.     }
  157.     cout << "Suma: " << s;
  158.  
  159.     return 0;
  160. }
  161.  
  162. //Zadanie 7
  163. #include <iostream>
  164.  
  165. using namespace std;
  166.  
  167. int main()
  168. {
  169.     int r,x;
  170.  
  171.     cout << "Podaj promien kola: ";
  172.     cin >> r;
  173.  
  174.     for (;r<=0;r++)
  175.     {
  176.         cout << "Podaj wlasciwa wartosc r: ";
  177.         cin >> r;
  178.     }
  179.     cout << "Pole kola: " << 3.14*r*r << endl;
  180.     cout << "Obwod kola: " << 2*3.14*r;
  181.     return 0;
  182. }
  183.  
  184. //Zadanie 8
  185. #include <iostream>
  186.  
  187. using namespace std;
  188.  
  189. int main()
  190. {
  191.     int x,y,mn,mx;
  192.  
  193.     cout << "Podaj liczby calkowite. W momencie podania 0 program zostanie zatrzymany" << endl;
  194.     cin >> x;
  195.  
  196.     mn=x;
  197.  
  198.     while (x!=0)
  199.     {
  200.         cin >> x;
  201.         if (x!=0)
  202.         {
  203.             y=x;
  204.  
  205.             if (y>mx)
  206.             {
  207.                 mx=y;
  208.             }
  209.             else if (y<mn)
  210.             {
  211.                 mn=y;
  212.             }
  213.         }
  214.     }
  215.     cout << "min: " << mn << ", max: " << mx;
  216.  
  217.     return 0;
  218. }
  219.  
  220. //Zadanie 9
  221. #include <iostream>
  222.  
  223. using namespace std;
  224.  
  225. int main()
  226. {
  227.     int a,b,x,y;
  228.  
  229.     cout << "Podaj 2 liczby: " << endl;
  230.     cin >> a >> b;
  231.     x=a*b;
  232.  
  233.     cout << "Podaj wynik mnozenia podanych liczb: ";
  234.     cin >> y;
  235.  
  236.     while (x!=y)
  237.     {
  238.         cout << "Podany wynik jest nieprawidlowy. Podaj poprawny wynik: ";
  239.         cin >> y;
  240.     }
  241.     cout << "Udalo ci sie podac poprawny wynik: " << x;
  242.     return 0;
  243. }
  244.  
  245. //Zadanie 10
  246. #include <iostream>
  247.  
  248. using namespace std;
  249.  
  250. int main()
  251. {
  252.     int a,b,i,j;
  253.     char x = '*';
  254.  
  255.     cout << "Podaj a i b:" << endl;
  256.     cin >> a >> b;
  257.  
  258.     for (j=0;j<b;j++)
  259.     {
  260.         for (i=0;i<a;i++)
  261.         {
  262.             cout << x;
  263.         }
  264.         cout << " " << endl;
  265.     }
  266.     return 0;
  267. }
  268.  
  269. //Zadanie 11
  270. #include <iostream>
  271.  
  272. using namespace std;
  273.  
  274. int main()
  275. {
  276.     int a,b,i,j;
  277.     char x = '*';
  278.     b=1;
  279.  
  280.     cout << "Podaj a: " << endl;
  281.     cin >> a;
  282.  
  283.     for (j=0;j<a;j++)
  284.     {
  285.         for (i=0;i<=j;i++)
  286.         {
  287.             cout << x;
  288.         }
  289.         cout << " " << endl;
  290.     }
  291.     return 0;
  292. }
  293.  
  294. //Zadanie 12
  295. #include <iostream>
  296.  
  297. using namespace std;
  298.  
  299. int main()
  300. {
  301.     int x,y,i;
  302.     y=0;
  303.     i=0;
  304.  
  305.     do
  306.     {
  307.         cout << "Podaj liczbe: " << endl;
  308.         cin >> x;
  309.         y=y+x;
  310.         i++;
  311.     }
  312.     while (y<=50);
  313.     cout << "Zsumowano " << i << " liczb" << endl << "Suma: " << y;
  314.  
  315.  
  316.     return 0;
  317. }
  318.  
  319. //Zadanie 13
  320. #include <iostream>
  321.  
  322. using namespace std;
  323.  
  324. int main()
  325. {
  326.     int x=0,i;
  327.  
  328.     for (i=1;i<=10;i++)
  329.     {
  330.         x+=i*i;
  331.     }
  332.     cout << "Ilosc cegiel w piramidzie: " << x << endl;
  333.     return 0;
  334. }
  335.  
  336. //Zadanie 14
  337. #include <iostream>
  338.  
  339. using namespace std;
  340.  
  341. int main()
  342. {
  343.     int x,s,i;
  344.     x=2;
  345.     s=0;
  346.  
  347.     for (i=1;i<30;i++)
  348.     {
  349.         x=x*2;
  350.         s=s+x;
  351.     }
  352.     cout << "Syn przez 30 dni uzbieral " << s << " zl";
  353.     return 0;
  354. }
  355.  
  356. //Zadanie 15
  357. #include <iostream>
  358.  
  359. using namespace std;
  360.  
  361. int main()
  362. {
  363.     int x,y,i;
  364.  
  365.     for (i=15;i>=1;i--)
  366.     {
  367.         x=x+i;
  368.     }
  369.     y=x*2;
  370.     cout << "ilosc cegiel: " << x << endl;
  371.     cout << "waga cegiel: " << y;
  372.  
  373.     return 0;
  374. }
  375.  
  376.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement