Practice5

Run Settings
LanguageC++
Language Version
Run Command
#include <cmath> #include <iostream> #include <iomanip> using namespace std; void task4() { int a3 = 0, a4 = 0, a5 = 0, a6 = 0; for (int i = 1; i <= 100; i++) { if (i % 3 == 1) a3++; if (i % 4 == 2) a4++; if (i % 5 == 3) a5++; if (i % 6 == 4) a6++; } cout << "amount of n%3=1 is" << a3 << "\namount of n%4=2 is" << a4 << "\namount of n%5=3 is" << a5 << "\namount of n%6=4 is" << a6; cout << endl << endl; } void task39() { int fibonacci[41] = { 1, 1 }; for (int i = 2; i <= 40; i++) { fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; } cout << "40th number of Fibonacci is" << " " << fibonacci[40] << endl << endl; } void task74() { int n, denominator = 1; double x, sum = 1; cout << "input 'x', then '1 < n <= 10'" << endl; cin >> x >> n; int *power = new int[n]; if (n > 1 && n <= 10) { for (int j = 0; j < n; j++) { power[j] = j + 1; } for (int i = 0; i < n; i++) { denominator *= power[i]; sum += pow(x, power[i]) / denominator; } cout << sum; } else cout << "n doesn't fit the condition"; cout << endl << endl; } void task109() { cout << "pow(x, 2) + x + 17, 0 <= x <= 15" << endl; int result, divider = 2; for (int i = 0; i <= 15; i++) { result = pow(i, 2) + i + 17; cout << result; while (result % divider != 0 && divider < result / 2) { divider++; } if (result % divider != 0) cout << " " << "is simple"; cout << endl; } cout << endl; } void task144() { int a, b, c, a2; for (a = 1; a < 25; a++) { for (b = 1; b < 25; b++) { for (c = 1; c < 25; c++) { if (a * a + b * b == c * c) cout << a << " " << b << " " << c << endl; } } } cout << endl; } void task179() { int sequence[10] = { 1, 1, 2, 3, 10, 4, 5, 6, 10, 0 }, amount = 1; for (int i = 0; i < 10; i++) { if (sequence[i] == sequence[i + 1]) amount++; } for (int j = 0; j < 10; j++) { cout << sequence[j] << " "; } cout << endl << "amount=" << amount << endl << endl; } void task214() { double aCurrent = 0.5, aPrevious, e; int number = 1; cout << "Input e..." << endl; cin >> e; cout << aCurrent; do { aPrevious = aCurrent; aCurrent = 1 / 2 * cos(aPrevious); cout << " " << aCurrent; number++; } while (abs(aCurrent - aPrevious) >= e); cout << endl << number << endl << endl; } void task249() { cout << setw(5) << "x:" << setw(10) << "y:" << endl; double y; for (double i = 0; i <= 23; i += 0.5) { y = i / cos(i); cout << setw(5) << i << setw(10) << y << endl; } cout << endl; } int main() { int number; int a = 1; cout << "Numbers of tasks are 4, 39, 74, 109, 144, 179, 214, 249 " << endl; while (a == 1) { cout << "Input the number of the task (0 to close the program)..." << endl; tryagain: cin >> number; cout << endl; if (number == 4) task4(); else if (number == 39) task39(); else if (number == 74) task74(); else if (number == 109) task109(); else if (number == 144) task144(); else if (number == 179) task179(); else if (number == 214) task214(); else if (number == 249) task249(); else if (number == 0) a = 0; else { cout << "Incorrect number, try again..." << endl; goto tryagain; } } }
Editor Settings
Theme
Key bindings
Full width
Lines