- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Лабораторная работа № 7
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
- •Void main()
Void main()
{
int h;
setlocale(LC_CTYPE, "Russian");
do
{
cout << "Введите" << endl;
cout << "1 - одномерный массив" << endl;
cout << "2 - работа с матрицей" << endl;
cout << "3 - Выход" << endl;
cin >> h;
switch(h)
{
case 1: arrau();
break;
case 2: matrix();
break;
case 3: break;
}
} while (h != 3);
}
void arrau()
{
const int n = 4;
int i, m = 0, m1, t = 0, size, c, p = 1;
int *a;
cout << "Введите размер массива" << endl;
cin >> size;
a = new int[size];
srand((unsigned)time(NULL));
for (i = 0; i < size; i++)
{
a[i] = rand() % 98 + 2;
}
cout << "Введите С" << endl;
cin >> c;
for (i = 0; i < size; i++)
{
if (a[i] > c) t++;
if (abs(a[i]) > m)
{
m = a[i];
m1 = i;
}
}
for (i = m1; i < size; ++i)
{
p *= a[i];
}
cout << t << " элементов больших чем C " << "произведение элементов " << p << endl;
delete[] a;
}
void matrix()
{
int **a, i, j, n = 0, row, col, m = 0;
cout << "Enter rows number" << endl;
cin >> row;
cout << "Enter colums number" << endl;
cin >> col;
srand((unsigned)time(NULL));
a = new int*[row];
for (i = 0; i < row; i++)
{
a[i] = new int[col];
for (j = 0; j < col; j++)
{
*(a[i] + j) = rand() % 10;
}
}
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
cout << *(a[i] + j) << " ";
m++;
if (m == col)
{
cout << endl;
m = 0;
}
}
}
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (*(a[i] + j) == 0)
{
n = i;
break;
}
}
if (n != 0) break;
}
cout << *(a[n] + 0) << endl;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
*(a[i] + j) -= *(a[n] + 0);
}
}
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
cout << *(a[i] + j) << " ";
m++;
if (m == col)
{
cout << endl;
m = 0;
}
}
}
for (int k = 0; k < row; k++)
{
delete a[k];
delete[] a;
}
}
Лабораторная работа №15
№1
Решение уравнения методом касательных x3 + 2x – 4
#include <iostream>
using namespace std;
double roots(double(*)(double),double, double, double);
double equation(double);
Void main()
{
int a = 1, b = 1.5;
double e = 0.0001, x1, x = 0;
if (((pow(a, 3) + 2 * a - 4) / (3 * pow(a, 2) + 2)) > 0) x1 = a;
else x1 = b;
cout << roots(*equation, x1, x, e) << endl;
}
double equation(double x)
{
return pow(x, 3) + 2 * x - 4;
}
double roots(double(*f)(double), double x1, double x, double e)
{
while (abs(x1 - x) > e)
{
x = x1;
x1 = x - f(x) / (3 * pow(x, 2) + 2);
}
return x1;
}
№2
Из предложения удалить все символы, совпадающие с символом, введенным с клавиатуры.
#include <iostream>
using namespace std;
char strieng(char *pStr1, int i);
Void main()
{
char *pStr1, *pStr2;
char a, *pa;
int i = 0, j = 0, size;
cout << "Enter size" << endl;
cin >> size;
pStr1 = new char[size + 1];
pStr2 = new char[size + 1];
cout << "Enter string" << endl;
cin >> pStr1;
cout << "Enter symbol" << endl;
cin >> a;
pa = &a;
for (i = 0; i < size; i++)
{
if (pStr1[i] != *pa)
{
pStr2[j] = pStr1[i];
j++;
}
}
cout << pStr2 << endl;
delete[] pStr1;
}
char strieng(char *pStr1, int i)
{
return pStr1[i];
}
Лабораторная работа №16
№1
#include <iostream>
#include <ctime>
using namespace std;
int negate(int h)
{
return -h;
}