5

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <cmath> #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 previous = 1, preprevious = 1, current; for (int i = 2; i <= 40; i++) { current = (previous + preprevious); preprevious = previous; previous = current; } cout << "40th number of Fibonacci is " << current << endl << endl; } void task74() { int n, denominator = 1; double x, sum = 1; cout << "input 'x', then 'n' (1 < n <= 10)" << endl; cin >> x >> n; if (n > 1 && n <= 10) { for (int i = 1; i <= n; i++) { denominator *= i; sum += pow(x, 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; for (int i = 0; i <= 15; i++) { result = pow(i, 2) + i + 17; cout << setw(3) << result; divider = 3; while (result % 2 != 0 && result % divider != 0 && divider < result / 2) { divider += 2; } if (result % 2 != 0 && result % divider != 0) cout << setw(2) << " is simple" << endl; } cout << endl; } void task144() { cout << "Pythagorean triples:\n"; int a, b, c; 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 << setw(2) << a << setw(4) << b << setw(5) << c << endl; } } } cout << endl; } void task179() { cout << "Input sequence of elements (more than 2), input 0 to end the sequence..." << endl; int currentElement, previousElement = 0, equalamount = 0, counter = 1; cin >> previousElement >> currentElement; if (previousElement == currentElement) equalamount+=2; previousElement = currentElement; cin >> currentElement; if (previousElement == currentElement) equalamount++; previousElement = currentElement; while (currentElement != 0) { cin >> currentElement; if (previousElement == currentElement && counter == 1) equalamount++; else counter = 0; previousElement = currentElement; } cout << "Amount of equal elements at the beginning is " << equalamount << 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, h = 0.1, a = 0, b = 3.14; for (double i = a; i <= b; i += h) { y = i / cos(i); cout << setw(5) << i << setw(10) << y << endl; } cout << endl; } int main() { int number; cout << "Numbers of tasks are 4, 39, 74, 109, 144, 179, 214, 249 " << endl; while (true) { cout << "Input the number of the task (0 to close the program)..." << endl; cin >> number; cout << endl; switch (number) { case 4: task4(); break; case 39: task39(); break; case 74: task74(); break; case 109: task109(); break; case 179: task179(); break; case 144: task144(); break; case 214: task214(); break; case 249: task249(); break; case 0: return 0; break; default: cout << "Incorrect number, try again" << endl; break; } } }
Editor Settings
Theme
Key bindings
Full width
Lines