Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HomeWork_6.cpp
- //
- #include <iostream>
- using namespace std;
- void task_1()
- {
- //the sum of all numbers
- int sum = 0;
- int a, i;
- start_1:
- cout << "Please enter a number from 1 to 500 - ";
- cin >> a;
- if (a < 0 || a > 500)
- {
- goto start_1;
- }
- i = a;
- for (; i < 501; i++)
- {
- sum = sum + a;
- cout << i << " - " << sum << "\n";
- }
- }
- void task_2()
- {
- //exponentiation
- int x,y,z;
- cout << "Enter x - ";
- cin >> x;
- cout << "Enter y - ";
- cin >> y;
- z = x;
- for (int i = x; i < y; i++)
- {
- z *= x;
- }
- cout << "The exponentiation of x - " << z << "\n";
- }
- void task_3()
- {
- //average
- int a = 1;
- int sum = 0,average;
- for (; a <= 1000; a++)
- {
- sum = sum + a;
- }
- average = sum / 1000;
- cout << "The average is - " << average << "\n";
- }
- void task_4()
- {
- //product of all numbers
- int num,product;
- cout << "Please enter a number from 1 to 20\n";
- cin >> num;
- for (int i = num; i < 21; i++)
- {
- num = num * i;
- product = num;
- cout << "\n " << product << "\n";
- }
- cout << "The product is - " << product << "\n";
- }
- void task_5()
- {
- //multiplication table
- int num,res;
- cout << "Please enter a number from 1 to 9 - ";
- cin >> num;
- for (int i = 2; i < 11; i++)
- {
- res = num * i;
- cout << num << " x " << i << " = " << res << "\n";
- }
- }
- int main()
- {
- //Task_1
- task_1();
- //Task_2
- task_2();
- //Task_3
- task_3();
- //Task_4
- task_4();
- //Task_5
- task_5();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement