Quick actions

cmd+k|ctrl+k

Navigation

Languages

Лабораторная 5

Snippet info

Language

Cpp

Visibility

public

Author

vladislav-taranenko

Created

2019-10-28T22:12:10Z

Updated

2019-12-12T20:13:03Z

#include <iostream>
#include <cmath>
#include <math.h>
#include <conio.h>
#include <iomanip>
using namespace std;

void Task18() 
//18.	Напечатать «столбиком» значения sin 2, sin 3, ..., sin 20
{
	cout << "Values of sin:"<<endl;
	for (double i = 2; i < 22; i++) 
	{
		cout << sin(i) << endl;
	}
	cin.get();
	return;
}

void Task53()
//53.	Найти сумму 2^2 + 2^3 + 2^4 + ... + 2^10 без возведения в степень
{

int s = 0;
int a = 2;
int i,g;
	for (i = 2; i < 11; i++) 
	{
	a= a * 2;
	g = s + a;
	cout << g << endl;
	}
	return;
}
void Task123()
//123. Вычислить сумму кодов всех символов, которые в цикле вводятся с клавиатуры до нажатия клавиши Esc
{
	cout << "\n\nPress any symbols,then press esc:" << endl;
	unsigned char ch;
	int s = 0;
    int d;
	ch = _getch();
	while (ch != (char)27)
	{
		d = s + (int)ch;
		cout << s << " + " << (int)ch << " = "<< d << endl;
		s += (int)ch;
		ch = _getch();
		cout << "Total sum of symbols: " << d << endl;	
	}
}
void Task158()
//158. Найти наименьшее общее кратное двух заданных натуральных чисел.
{
	int First, Second, c;
	double NOK;
	cout << "\n\nInput first number, then input second number"<<endl;
	cin >> First >> Second;
	c = First * Second;
	while (First != Second)
	{
		if (First > Second)
		{
			First -= Second;
		}
		else
		{
			Second -= First;
		}
	}
	NOK = c / First;
	cout << "NOK: " << NOK << endl;
	return;
}

void Task193()
//193. Выяснить, является ли заданное число m членом геометрической прогрессии, первый член которой равен g, а знаменатель — z
{
	int g, z, m;
	cout << "\n\nInput g\n>";
	cin >> g;
	cout << "Input z\n>";
	cin >> z;
	cout << "Input m\n>";
	cin >> m;

	while (2 > 1)
	{
		if (g == m)
		{
			cout << "M: " << m << " Is a member of the geometric progression" << endl;
		}
		g = g * z;
		if (g > m)
		{
			cout << "M: " << m << " Not a member of the geometric progression" << endl;
		}
	}
}
void Task228()
{
	//Task 231. Determine the values of the function ctg(x) + 1 in range [a,b] with step h.
	float x, b, h;
	cout << "\nEnter the beginning and the end of range [a,b]: ";
	cin >> x >> b;
	cout << "Enter the step h: ";
	cin >> h;
	cout << "Function ctg(x) + 1. Range [" << x << "," << b << "] with step " << h << ": \n\n";
	cout << setw(20) << "X" << setw(20) << "ctg(x) + 1" << endl << setfill('-') << setw(45) << "-" << endl;
	if (x <= b) {
		for (x; x <= b; x += h) {
			cout << setfill(' ') << setw(20) << x << setw(20) << 1/tan(x) + 1 << endl;
		}
	}
	else if (x > b) {
		for (x; x > b; x -= h) {
			cout << setfill(' ') << setw(20) << x << setw(20) << 1/tan (x) + 1 << endl;
		}
	}

}
void Task263()
//263. Написать программу вычисления функции при a = 2 ;b = -2 . Аргумент x принимает значения от –6 до 4 с шагом 1.
{
	int main(int argc, char* argv[]);
	{
		double a, b, h, x, result = 0;
		a = 2;
		b = -2;
		for (x = -6; x<=4; x++)
		{
			result = 0.2 * a * b * x - 5 * (tan(x)*tan(x)) * 3 * (x * x) + 3 * sqrt(a - b * x);
			cout << result << endl;
		}

		system("pause");
		return 0;
	}


}

int main()
{
	Task18();
	Task53();
    Task123();
	Task158();
	Task193();
	Task228();
	Task263();
}
INFO