Z4) #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std;
int main() { setlocale(LC_ALL, "Rus"); double A[10], B[10], C[10]; for (int i = 0; i < 10; i++) { A[i] = sin(i); B[i] = sqrt(i); C[i] = A[i] + B[i]; }
cout << "A- "; for (int i = 0; i < 10; i++) cout << fixed << setprecision(4) << A[i] << " ";
cout << endl << "B- "; for (int i = 0; i < 10; i++) cout << B[i] << " ";
cout << endl << "C- "; for (int i = 0; i < 10; i++) cout << C[i] << " "; cout << endl << endl; double kol = 0;
for (int i = 0; i < 10; i++) if (A[i] > 0) kol++; cout << "Количество полож. елемент в А= " << fixed << setprecision(0)<< kol << endl; kol = 0;
for (int i = 0; i < 10; i++) if (B[i] > 1, 7 && B[i] < 2.6) kol += B[i]; cout << "Средн. арифм. в B= " << fixed << setprecision(4) << kol / 10 << endl << "Измененный С- ";
for (int i = 0; i < 10; i++) { if (C[i] >= 0) C[i] *= 2; else C[i]--; cout << C[i]<<" "; } double max=0, min=C[0]; for (int i = 0; i < 10; i++) { if (C[i] > max) max = C[i]; if (C[i] < min) min = C[i]; } cout << endl << "Минимальный в С= " << min << endl << "Максимальный в С= " << max << endl;
system("pause"); }
Z5) #include "stdafx.h" #include <iostream> using namespace std; bool Simple(int N) { bool result = true; for (int k = 2; k <= N / 2; k++) if (N%k == 0) result = false; return result; }
int main() { setlocale(0, "rus"); cout << "Введите размер массива: "; int n; cin >> n; int* m = new int[n]; int i = 0, num = 1; bool e = false; while (e != true) { if (Simple(num)) { m[i] = num; i++; } num++; if (i == n) e = true; } for (i = 0; i<n; i++) cout << m[i] << " "; cout << endl; for (int i = 0; i < n; i++) if (m[i] % 10 == 3) cout << m[i]<<" "; cout << endl; system("pause"); delete[] m; return 0; }
Answers & Comments
Z4)
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
setlocale(LC_ALL, "Rus");
double A[10], B[10], C[10];
for (int i = 0; i < 10; i++) {
A[i] = sin(i);
B[i] = sqrt(i);
C[i] = A[i] + B[i];
}
cout << "A- ";
for (int i = 0; i < 10; i++) cout << fixed << setprecision(4) << A[i] << " ";
cout << endl << "B- ";
for (int i = 0; i < 10; i++) cout << B[i] << " ";
cout << endl << "C- ";
for (int i = 0; i < 10; i++) cout << C[i] << " ";
cout << endl << endl;
double kol = 0;
for (int i = 0; i < 10; i++) if (A[i] > 0) kol++;
cout << "Количество полож. елемент в А= " << fixed << setprecision(0)<< kol << endl;
kol = 0;
for (int i = 0; i < 10; i++)
if (B[i] > 1, 7 && B[i] < 2.6)
kol += B[i];
cout << "Средн. арифм. в B= " << fixed << setprecision(4) << kol / 10 << endl << "Измененный С- ";
for (int i = 0; i < 10; i++) {
if (C[i] >= 0)
C[i] *= 2;
else C[i]--;
cout << C[i]<<" ";
}
double max=0, min=C[0];
for (int i = 0; i < 10; i++) {
if (C[i] > max) max = C[i];
if (C[i] < min) min = C[i];
}
cout << endl << "Минимальный в С= " << min << endl << "Максимальный в С= " << max << endl;
system("pause");
}
Z5)
#include "stdafx.h"
#include <iostream>
using namespace std;
bool Simple(int N) {
bool result = true;
for (int k = 2; k <= N / 2; k++)
if (N%k == 0) result = false;
return result;
}
int main() {
setlocale(0, "rus");
cout << "Введите размер массива: "; int n; cin >> n;
int* m = new int[n];
int i = 0, num = 1;
bool e = false;
while (e != true) {
if (Simple(num)) {
m[i] = num;
i++;
}
num++;
if (i == n) e = true;
}
for (i = 0; i<n; i++) cout << m[i] << " ";
cout << endl;
for (int i = 0; i < n; i++) if (m[i] % 10 == 3) cout << m[i]<<" ";
cout << endl;
system("pause");
delete[] m;
return 0;
}