DawidG

Zadania z pętli c++

Dec 6th, 2020 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. Zadanie 1 wersja "for"
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     for (int i = 1; i <= 100; i++)
  10.     {
  11.         cout << i << endl;
  12.     }
  13. return 0;
  14. }
  15.  
  16. Zadanie 1 wersja "while"
  17.  
  18. #include <iostream>
  19.  
  20. using namespace std;
  21. int i = 1;
  22.  
  23. int main()
  24. {
  25.     while (i < 101);
  26.     {
  27.         cout << i;
  28.         i++;
  29.     }
  30.     return 0;
  31. }
  32. Zadanie 1 wersja "dowhile"
  33.  
  34. #include <iostream>
  35.  
  36. using namespace std;
  37. int i = 1;
  38.  
  39. int main()
  40. {
  41.     do
  42.     {
  43.         cout << i << endl;
  44.         i++;
  45.     }while (i < 101);
  46.  
  47.     return 0;
  48. }
  49. Zadanie 2
  50. #include <iostream>
  51.  
  52. using namespace std;
  53.  
  54. int a, b;
  55.  
  56. int main()
  57. {
  58.     cout << "Wprowadz I kraniec przedzialu: ";
  59.     cin >> a;
  60.  
  61.     cout << "Wprowadz II kraniec przedzialu: ";
  62.     cin >> b;
  63.  
  64.     do
  65.     {
  66.         cout << a << endl;
  67.         a++;
  68.     } while (a <= b);
  69.     return 0;
  70. }
  71. Zadanie 3
  72. #include <iostream>
  73.  
  74. using namespace std;
  75. int n, i, b;
  76.  
  77. int main()
  78. {
  79.     cout << "Podaj liczbe z ktorej chcesz obliczyc silnie: " ;
  80.     cin >> n;
  81.  
  82.     while (n < 0)
  83.     {
  84.         cout << "Nie mozna obliczyc z liczby ujemnej. Podaj liczbe nieujemna! ";
  85.         cin >> n;
  86.  
  87.     }
  88.  
  89.     if (n == 0)
  90.  
  91.     {
  92.         cout << "Silnia z Liczby" << n << "0!=1 " << endl;
  93.     }
  94.     else
  95.  
  96.     {
  97.         b = 1;
  98.         for (i = n; i >= 2; i = i - 1)
  99.         {
  100.  
  101.             b = b * n;
  102.  
  103.         }
  104.         cout << "Silnia wynosi:" << b;
  105.     }
  106.  
  107.     return 0;
  108. }
  109.  
  110. Zadanie 4
  111. #include <iostream>
  112.  
  113. using namespace std;
  114.  
  115. int a;
  116.  
  117. int main()
  118. {
  119.     cout << "Wyswietl wszystkie liczby dwucyfrowe " << endl;
  120.  
  121.  
  122.     for (a = 10; a<= 99; a++)
  123.     {
  124.         if (a % 4 == 0)
  125.         cout <<a<< endl;
  126.     }
  127.     return 0;
  128. }
  129. Zadanie 5
  130.  
  131. #include <iostream>
  132.  
  133. using namespace std;
  134.  
  135. int a, i, n;
  136.  
  137. int main()
  138. {
  139.     cout << "Podaj pierwsza liczbe: ";
  140.     cin >> n;
  141.  
  142.     cout << "Co ile ma przeskakiwac: ";
  143.     cin >> a;
  144.  
  145.     for (int i = n; i <= 200; i = i + a)
  146.     {
  147.         cout << i << endl;
  148.     }
  149.  
  150. return 0;
  151. }
  152.  
  153. Zadanie 6
  154.  
  155. #include <iostream>
  156.  
  157. using namespace std;
  158.  
  159. int main() {
  160.  
  161.     cout << "Podaj 10 liczb" << endl;
  162.     int suma = 0;
  163.  
  164.     for (int i = 1; i <= 10;i++)
  165.     {
  166.         cout << "Podaj " << i << " liczbe: ";
  167.         int wprowadz = 0;
  168.         cin >> wprowadz;
  169.         suma += wprowadz;
  170.     }
  171.  
  172.     cout << "Suma 10 liczb wynosi " << suma << endl;
  173.  
  174.     return 0;
  175. }
  176.  
  177. Zadanie 7
  178.  
  179. #include <iostream>
  180.  
  181. using namespace std;
  182.  
  183. float r, pole, obwod;
  184.  
  185. int main()
  186. {
  187.     do
  188.     {
  189.         cout << "Podaj promien: " ;
  190.         cin >> r;
  191.  
  192.     } while (r <= 0);
  193.  
  194.     obwod = 2 * 3.14 * r;
  195.     pole = 3.14 * r * r;
  196.  
  197.     cout << "Pole kola: " << pole << endl;
  198.     cout << "Obwod kola: " << obwod << endl;
  199.     return 0;
  200. }
  201.  
  202. Zadanie 10
  203.  
  204. #include <iostream>
  205.  
  206.  
  207. using namespace std;
  208.  
  209. int szerokosc, wysokosc;
  210.  
  211. int main()
  212. {
  213.    
  214.  
  215.     cout << "Podaj szerokosc: ";
  216.     cin >> szerokosc;
  217.  
  218.     cout << "Podaj wysokosc=: ";
  219.     cin >> wysokosc;
  220.  
  221.     cout << endl;
  222.     for (int i = 1; i <= wysokosc; i++)
  223.     {
  224.         for (int j = 1; j <= szerokosc; j++)
  225.             cout << "*";
  226.         cout << endl;
  227.     }
  228.  
  229.     cout << endl;
  230.     return 0;
  231. }
  232.  
  233. Zadanie 12
  234.  
  235. #include <iostream>
  236.  
  237. using namespace std;
  238.  
  239. int liczba, suma = 0, ilosc = 0;
  240.  
  241. int main()
  242. {
  243.     cout << "Podaj 10 liczb" << endl;
  244.  
  245.     for (int i = 1; i <= 10; i++)
  246.     {
  247.         cout << " Podaj " << i << " liczbe" << endl;
  248.         cin >> liczba;
  249.         suma = suma + liczba;
  250.         ilosc++;
  251.         if (suma > 50)
  252.         {
  253.             cout << "Suma podanych liczb przekroczyla 50" << endl;
  254.             cout << "Podano " << ilosc << " liczb ktorych suma wyniosla " << suma << endl;
  255.             return 0;
  256.         }
  257.     }
  258.  
  259.  
  260.     return 0;
  261. }
Add Comment
Please, Sign In to add comment