Ответы на вопрос:
Відповідь:
1.
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void randarr(int *A, int N){
for(int i = 0; i < N; i++){
A[i] = rand() % 10 + 1;
}
}
void printarr(int *A, int N){
for(int i = 0; i < N; i++){
cout << A[i] << " ";
}
}
void sortarr(int *A, int N){
for(int i = 0; i < N; ++i){
int smallest = i;
for(int j = i + 1; j < N; ++j){
if(A[j] < A[smallest]){
smallest = j;
}
}
swap(A[i] , A[smallest]);
}
}
int main(){
srand(time(NULL));
setlocale(LC_ALL, "Rus");
int N;
cout << "Введите кол-во елементов массива: ";
cin >> N;
int *A = new int[N];
randarr(A,N);
printarr(A,N);
sortarr(A,N);
cout << "\n";
printarr(A,N);
delete[] A;
return 0;
}
2.
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void randarr(int *B, int N){
for(int i = 0; i < N; i++){
B[i] = rand() % 10 + 1;
}
}
void printarr(int *B, int N){
for(int i = 0; i < N; i++){
cout << B[i] << " ";
}
}
void sortarr(int *B, int N){
int twoelements;
for(int j = 0; j < N - 1; j++){
twoelements = j;
}
swap(B[0] , B[twoelements]);
}
int main(){
srand(time(NULL));
setlocale(LC_ALL, "Rus");
int N;
cout << "Введите кол-во елементов массива: ";
cin >> N;
int *B = new int[N];
randarr(B,N);
printarr(B,N);
sortarr(B,N);
cout << endl;
printarr(B,N);
delete[] B;
return 0;
}
3.
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void randarr(int *A, int N){
for(int i = 0; i < N; i++){
A[i] = rand() % 10 + 1;
}
}
void printarr(int *A, int N){
for(int i = 0; i < N; i++){
cout << A[i] << " ";
}
}
void twoarr(int *A, int *B, int N){
for(int i = 0; i < N; i++){
B[i] = A[i] * (-1);
}
}
void sortarrtobig(int *A, int N){
for(int i = 0; i < N; ++i){
int smallest = i;
for(int j = i + 1; j < N; ++j){
if(A[j] < A[smallest]){
smallest = j;
}
}
swap(A[i] , A[smallest]);
}
}
void sortarrtosmall(int *A, int N){
for(int i = 0; i < N; ++i){
int smallest = i;
for(int j = i + 1; j < N; ++j){
if(A[j] > A[smallest]){
smallest = j;
}
}
swap(A[i] , A[smallest]);
}
}
int main(){
srand(time(NULL));
setlocale(LC_ALL, "Rus");
int N;
cout << "Введите кол-во елементов массива: ";
cin >> N;
int *A = new int[N];
int *B = new int[N];
randarr(A,N);
cout << "Первый массив: ";
printarr(A,N);
cout << "\nВторой массив: ";
twoarr(A,B,N);
printarr(B,N);
cout << "\nСортируем первый массив по убыванию" << endl;
sortarrtosmall(A,N);
cout << "Первый массив: ";
printarr(A,N);
cout << "\nСортируем второй массив по возрастанию" << endl;
sortarrtobig(B,N);
cout << "Второй массив: ";
printarr(B,N);
delete[] A;
delete[] B;
return 0;
}
PascalABC.NET 3.6.2
begin
var func : real -> real := k ->(k + 1)/(k**2 + 1);
var s: real := 0;
var n := readinteger();
for var i := 1 to n do s += func(i);
s.Println;
end.
input/output:
>>> 9
>>> 3.13448882499098
Популярно: Информатика
-
mastermax21703.10.2020 18:06
-
Oles111521.08.2020 00:12
-
чурка282918.12.2020 16:46
-
илья198822.02.2022 12:03
-
liliakhalilova13.04.2021 14:33
-
HellyBellyGaz16.06.2020 07:20
-
temauvarov22828.07.2020 22:48
-
Арсен07704.05.2021 02:01
-
dpichuzhkina21.02.2023 20:59
-
юлиядзудзе17.08.2020 16:30