Advertisement
jelyslime

Cicles homework

Nov 28th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. Zadacha 1:
  2.  
  3. #include <iostream>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11.  
  12.     int i = 0;
  13.     unsigned int n;
  14.     cout << "Vuvedete chislo" << endl;
  15.     cin >> n;
  16.    
  17.  
  18.     while (n > 0)
  19.     {
  20.         n = n / 10;
  21.         i++;
  22.    
  23.     }
  24.  
  25.     cout << i << endl;
  26.    
  27.     return 0;
  28.    
  29. }
  30.  
  31.     Zadacha 2:
  32.  
  33. #include <iostream>
  34.  
  35.  
  36.  
  37. using namespace std;
  38.  
  39.  
  40. int main() {
  41.  
  42.     int sum = 0, y = 0;
  43.     int i = 0;
  44.     unsigned int n;
  45.     cout << "Vuvedete chislo" << endl;
  46.     cin >> n;
  47.    
  48.  
  49.     while (n > 0)
  50.     {
  51.         y = n % 10;
  52.         sum += y;
  53.        
  54.         n = n / 10;
  55.        
  56.     }
  57.  
  58.     cout << sum << endl;
  59.    
  60.     return 0;
  61.    
  62. }
  63.  
  64.     Zadacha 3
  65.  
  66. #include <iostream>
  67.  
  68.  
  69. using namespace std;
  70.  
  71.  
  72. int main() {
  73.  
  74.     int sum = 0, y = 0;
  75.     int i = 0;
  76.     unsigned int n;
  77.     cout << "Vuvedete chislo" << endl;
  78.     cin >> n;
  79.    
  80.  
  81.     while (n > 0)
  82.     {
  83.         y = n % 10;
  84.         sum = sum * 10 + y;
  85.        
  86.         n = n / 10;
  87.        
  88.     }
  89.  
  90.     cout << sum << endl;
  91.    
  92.     return 0;
  93.    
  94. }
  95.  
  96.  
  97.     Zadacha 4:
  98.  
  99. #include <iostream>
  100.  
  101.  
  102. using namespace std;
  103.  
  104.  
  105. int main() {
  106.  
  107.  
  108.     int for0 = 0, for1 = 0, for2 = 0 ,for3 = 0 , for4 = 0, for5 = 0, for6 = 0, for7 = 0, for8 = 0, for9 = 0;
  109.     int y = 0;
  110.     unsigned int n;
  111.     cout << "Vuvedete chislo" << endl;
  112.     cin >> n;
  113.    
  114.  
  115.     while (n > 0)
  116.     {
  117.         y = n % 10;
  118.        
  119.         if (y == 0)
  120.         {
  121.             for0++;
  122.         }
  123.         if (y == 1)
  124.         {
  125.             for1++;
  126.         }
  127.         if (y == 2)
  128.         {
  129.             for2++;
  130.         }
  131.         if (y == 3)
  132.         {
  133.             for3++;
  134.         }
  135.         if (y == 4)
  136.         {
  137.             for4++;
  138.         }
  139.         if (y == 5)
  140.         {
  141.             for5++;
  142.         }
  143.         if (y == 6)
  144.         {
  145.             for6++;
  146.         }
  147.         if (y == 7)
  148.         {
  149.             for7++;
  150.         }
  151.         if (y == 8)
  152.         {
  153.             for8++;
  154.         }
  155.         if (y == 9)
  156.         {
  157.             for9++;
  158.         }
  159.        
  160.  
  161.         n = n / 10;
  162.        
  163.     }
  164.  
  165.     cout << " 0/" << for0 << " 1/" << for1 << " 2/" << for2 << " 3/" << for3 << " 4/" << for4 << " 5/" << for5 << " 6/" << for6
  166.         << " 7/" << for7 << " 8/" << for8 << " 9/" << for9 << endl;
  167.    
  168.     return 0;
  169.    
  170. }
  171.  
  172.  
  173.     Zadacha 5:
  174.  
  175. #include <iostream>
  176.  
  177.  
  178.  
  179. using namespace std;
  180.  
  181.  
  182. int main() {
  183.  
  184.     unsigned int colums;
  185.     char sumbol = 'a';
  186.     cout << "Vuvedete simvol i broi redove" << endl;
  187.     cin >> sumbol >> colums;
  188.     int j, k = 0;
  189.    
  190.     for (int i = 1; i <= colums ; i++)
  191.     {
  192.         for (j = colums - 1; j >= i; j--) {
  193.  
  194.             cout << " ";
  195.         }
  196.  
  197.         for (k = 1; k <= (2 * i - 1); k++) {
  198.  
  199.             cout << sumbol;
  200.         }
  201.         cout << endl;
  202.  
  203.     }
  204.    
  205.    
  206.     return 0;
  207.    
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement