FilipKinderman

Pętle część 2

Dec 14th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. Zad 3
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int i,b;
  8.     int a=1;
  9.     cout<<"Wpisz liczbe"<<endl;
  10.     cin>>b;
  11.  
  12.     if(b<0)
  13.     {
  14.         cout<<"Wprowadzono bledna liczbe"<< endl;
  15.     }
  16.     else if (b==0)
  17.     {
  18.         cout<<"silna 0=1"<< endl;
  19.     }
  20.     else
  21.     {
  22.         for (i=1; i<=b; i++)
  23.         {
  24.             a=i*a;
  25.  
  26.         }
  27.        cout<<a<<endl;
  28.     }
  29. return 0
  30. }
  31.  
  32. zad 7
  33. #include <iostream>
  34.  
  35. using namespace std;
  36.  
  37. int main() {
  38.     int a;
  39.     float p, ob;
  40.  
  41.     do
  42.     {
  43.         cout<<"Wpisz dlugosc promienia"<<endl;
  44.         cin>>a;
  45.     }
  46.     while (a<=0);
  47.     p=3.14*a*a;
  48.     ob=2*3.14*a;
  49.  
  50.     cout<<"Pole="<<p<<endl;
  51.     cout<<"Obwod="<<ob<<endl;
  52.  
  53. }
  54.  
  55.  
  56. zad 8
  57.   #include <iostream>
  58.  
  59. using namespace std;
  60. int main()
  61. {
  62.     int i;
  63.  
  64.     int a;
  65.  
  66.     int minimal;
  67.  
  68.     int maksymal;
  69.  
  70.     cout << "Wpisz liczbe:" << endl;
  71.     cin >> a;
  72.     minimal = a;
  73.     maksymal = a;
  74.  
  75.     while (a != 0)
  76.     {
  77.         if (minimal > a)
  78.             minimal = a;
  79.  
  80.  
  81.         if (maksymal < a)
  82.             maksymal = a;
  83.         cin >> a;
  84.     }
  85.     cout << "Wartosc maksymalna wsrod podanych liczb jest rowna: "<< maksymal << endl;
  86.     cout << "Wartosc minimalna wsrod podanych liczb jest rowna: "<< minimal << endl;
  87. }
  88.  
  89.  
  90. Zad 10
  91.    #include <iostream>
  92. using namespace std;
  93.  
  94. int main(int argc, char *argv[])
  95. {
  96.  int wysokosc,szerokosc;
  97.  
  98.  cout << "szerokosc="<<endl;
  99.  cin >> szerokosc;
  100.  
  101.  cout << "wysokosc="<<endl;
  102.  cin >> wysokosc;
  103.  
  104.  cout << endl;
  105.  for(int i=1; i <= wysokosc; i++)
  106.  {
  107.  for (int k=1; k <= szerokosc; k++)
  108.  cout << "*";
  109.  cout << endl;
  110.  }
  111.  
  112.  cout << endl;
  113.  system("PAUSE");
  114.  
  115.  return 0;
  116. }
  117.  
  118. Zad 11
  119.  #include <iostream>
  120.  using namespace std;
  121.  int main()
  122.  
  123. {
  124.    int a;
  125.  
  126.    cout << "Wpisz dlugosc boku: "<<endl;
  127.    cin>>a;
  128.  
  129.  
  130.    for(int i=a;i>0; i--)
  131.    {
  132.  
  133.  
  134.     for(int j=0;j<i;j++)
  135.     cout<<"*";
  136.     cout<<endl;
  137.    }
  138.  
  139.  
  140.    return 0;
  141.  
  142. }
  143.  
  144. Zad 12
  145.  #include <iostream>
  146.  
  147.  using namespace std;
  148.  
  149. int main()
  150. {
  151.    int a = 0;
  152.  
  153.    while (a < 50)
  154.  
  155.    {
  156.       int b = 0;
  157.       cin>>b;
  158.       a += b;
  159.    }
  160.    return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment