FilipKinderman

Pętle 1 część

Dec 8th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. Zadanie 1
  2.  
  3. #include <iostream>
  4. using namespace std;
  5. int main()
  6. {
  7.     int i;
  8.  
  9.     for (i = 1; i <= 100; i++)
  10.     {
  11.         cout << i << endl;
  12.     }
  13.     i = 1;
  14.     while (i <= 100)
  15.     {
  16.         cout << i << endl;
  17.         i++;
  18.     }
  19.     i = 1;
  20.     do
  21.     {
  22.         cout << i << endl;
  23.         i++;
  24.     } while (i <= 100);
  25. }
  26.  
  27.  
  28. Zadanie 2
  29.  
  30. #include <iostream>
  31. using namespace std;
  32. int main()
  33. {
  34.     int i;
  35.     int x, y;
  36.     int tymczasowa;
  37.  
  38.     cout << "Podaj pierwszy kraniec przedzialu" << endl;
  39.     cin >> x;
  40.     cout << "Podaj drugi kraniec przedzialu" << endl;
  41.     cin >> y;
  42.  
  43.     if (y < x)
  44.     {
  45.         tymczasowa = y;
  46.         y = x;
  47.         x = tymczasowa;
  48.     }
  49.     cout << "\n";
  50.     for (i = x; i <= y; i++)
  51.     {
  52.         if (i % 3 == 0)
  53.         {
  54.             cout << i << " liczba jest podzielna przez 3" << endl;
  55.         }
  56.         else
  57.         {
  58.             cout << i << " liczba nie podzielna przez 3" << endl;
  59.         }
  60.     }
  61.  
  62. }
  63.  
  64.  
  65. Zadanie 4
  66.  
  67. #include <iostream>
  68. using namespace std;
  69. int main()
  70. {
  71.     int i;
  72.    
  73.     for (i = 10; i < 100; i++)
  74.     {
  75.         if (i % 4 == 0)
  76.         {
  77.             cout << i << endl;
  78.         }
  79.     }
  80. }
  81.    
  82.  
  83.  
  84. Zadanie 5
  85.  
  86. #include <iostream>
  87. using namespace std;
  88. int main()
  89. {
  90.     int x,y=0;
  91.  
  92.     cout << "Podaj przeskok:" << endl;
  93.     cin >> x;
  94.  
  95.     do
  96.     {
  97.         cout << y << " ";
  98.         y += x;
  99.     } while (y <= 200);
  100. }
  101.  
  102.  
  103.  
  104. Zadanie 6
  105.  
  106. #include <iostream>
  107. using namespace std;
  108. int main()
  109. {
  110.     int i;
  111.     int x,y=0;
  112.  
  113.     for (i = 0; i < 10; i++)
  114.     {
  115.         cout << "Podaj kolejno 10 liczb" << endl;
  116.         cin >> x;
  117.         y += x;
  118.     }
  119.     cout << "Suma 10 liczb wynosi: " << y << endl;
  120.  
  121. }
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment