Advertisement
GarikK

homeWokr_6_forst_part

Feb 18th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. // HomeWork_6.cpp
  2. //
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. void task_1()
  7. {
  8.     //the sum of all numbers
  9.     int sum = 0;
  10.     int a, i;
  11. start_1:
  12.     cout << "Please enter a number from 1 to 500 - ";
  13.     cin >> a;
  14.     if (a < 0 || a > 500)
  15.     {
  16.         goto start_1;
  17.     }
  18.     i = a;
  19.     for (; i < 501; i++)
  20.     {
  21.         sum = sum + a;
  22.         cout << i << " - " << sum << "\n";
  23.     }
  24.    
  25. }
  26.  
  27. void task_2()
  28. {
  29.     //exponentiation
  30.     int x,y,z;
  31.     cout << "Enter x - ";
  32.     cin >> x;
  33.     cout << "Enter y - ";
  34.     cin >> y;
  35.     z = x;
  36.     for (int i = x; i < y; i++)
  37.     {
  38.         z *= x;
  39.     }
  40.    
  41.     cout << "The exponentiation of x - " << z << "\n";
  42. }
  43. void task_3()
  44. {
  45.     //average
  46.     int a = 1;
  47.     int sum = 0,average;
  48.     for (; a <= 1000; a++)
  49.     {
  50.         sum = sum + a;
  51.     }
  52.     average = sum / 1000;
  53.     cout << "The average is - " << average << "\n";
  54. }
  55. void task_4()
  56. {
  57.     //product of all numbers
  58.     int num,product;
  59.     cout << "Please enter a number from 1 to 20\n";
  60.     cin >> num;
  61.     for (int i = num; i < 21; i++)
  62.     {
  63.         num = num * i;
  64.         product = num;
  65.         cout << "\n " << product << "\n";
  66.        
  67.     }
  68.     cout << "The product is - " << product << "\n";
  69. }
  70. void task_5()
  71. {
  72.     //multiplication table
  73.     int num,res;
  74.     cout << "Please enter a number from 1 to 9 - ";
  75.     cin >> num;
  76.     for (int i = 2; i < 11; i++)
  77.     {
  78.         res = num * i;
  79.         cout << num << " x " << i << " = " << res << "\n";
  80.     }
  81.    
  82. }
  83. int main()
  84. {
  85.     //Task_1
  86.     task_1();
  87.     //Task_2
  88.     task_2();
  89.     //Task_3
  90.     task_3();
  91.     //Task_4
  92.     task_4();
  93.     //Task_5
  94.     task_5();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement