Files
dz2/main.cpp
2024-11-02 17:13:07 +03:00

107 lines
2.3 KiB
C++

#include <iostream>
#include <math.h>
using namespace std;
void z1(){
double R,r,h;
cout << "R = ";
cin >> R;
cout << "r = ";
cin >> r;
cout << "h = ";
cin >> h;
if (R <= 0 or r <= 0 or h <= 0) {
cout << "Нет решений"<<endl;
}
float l = sqrt(pow(R-r, 2) + pow(h, 2));
float S = M_PI * (pow(R, 2) + (R + r) * l + pow(r, 2));
float V = (1.0/3) * M_PI * h * (pow(R, 2) + R * r + pow(r, 2));
cout << "S= " << S << endl;
cout << "V= " << V << endl;
}
void z2(){
double x,a,y;
cout<<"Введите x: ";
cin>>x;
cout<<"Введите a: ";
cin>>a;
if (abs(x)<1){
if (x!=0){
y=a*log(abs(x));
cout<<"Результат: "<<y;}
else{
cout<<"Логарифма от нуля не бывает";
}
}
if (abs(x)>=1){
if ((a-pow(x,2))<=0){
cout<<"Под корнем не может быть отрицательных чисел"<<endl;
}
else{
y=sqrt(a-pow(x,2));
cout<<"Результат: "<<y<<endl;
}
}
}
void z3(){
double x,y,b,z;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "b = ";
cin >> b;
if (((b-x)<0) or ((b-y)<0)){
cout<<"Под корнем или логарифмом отрицательное число"<<endl;
}
else{
z=log(b-y)*sqrt(b-x);
cout<<"Результат:"<<endl<<z<<endl;}
}
void z4(){
int n;
cout<<"Введите n: ";
cin>>n;
if (n<=0){
cout<<"цикла не будет";
}
else{
for (int i=0;i<10;i++) {
cout<<n++<<endl;
}
}
}
void z5(){
double y;
float x=-4;
do {
y=(pow(x,2)-2*x+2)/(x-1);
if (x!=1){
cout<<"X="<<x<<" Y="<<y<<endl;}
else{
cout<<"X="<<x<<"\t Y-не определен"<<endl;
}
x=x+0.5;
}
while (x<=4);
}
int main() {
setlocale(LC_ALL, "");
// cout<<"Задание 1"<<endl;
// z1();
cout<<"Задание 2"<<endl;
z2();
// cout<<"Задание 3"<<endl;
// z3();
// cout<<"Задание 4"<<endl;
// z4();
// cout<<"Задание 5"<<endl;
// z5();
}