1 задание
#include<iostream>#include<ctime>
using namespace std;
int main(){ srand(time(NULL)); int N, min = 10, range = 30; int *arr; cout << "enter size of arr(enter N) : "; cin >> N; arr = new int [N]; for(int i = 1; i <= N;i++) arr[i] = rand()%(range + 1) + min; cout << "arr : " << endl; for(int i = 1; i <= N;i++) cout << arr[i] << " " ; cout << endl; for(int i = 1; i <= N;i++){ if(arr[i] > 25) arr[i] = i*i; else arr[i] = arr[i] + 5; } cout << "NEWarr : " << endl; for(int i = 1; i <= N;i++) cout << arr[i] << " " ;}
2 задание
#include<iostream>
using namespace std;int main(){ int N; int *arr; cout << "enter size of arr(enter N) : "; cin >> N; arr = new int [N]; for(int i = 1; i <= N;i++) cin >> arr[i];
int temp = arr[1]; int templ = arr[N];
arr[1] = arr[2]; arr[2] = temp; arr[N] = arr[N-1]; arr[N-1] = templ; cout << "new arr : "; for(int i = 1; i <= N;i++) cout << arr[i] << " " ;}
на С++ как то так
int main(){ srand(time(NULL)); int N, a, sum = 0, ten = 10, index = 0; int *arr; cout << "enter size of arr(enter N) : "; cin >> N; arr = new int [N]; for(int i = 1; i <= N;i++) arr[i] = rand()%25;
cout << "arr : " << endl; for(int i = 1; i <= N;i++) cout << arr[i] << " " ; cout << endl;
cout << "enter a : " ; cin >> a;
for(int i = 1; i <= N;i++) { if(arr[i] == a) index = i;
} if(index != 0) { for(int i = index + 1; i <= N;i++) sum = sum + arr[i]; } if(sum == 0) cout << "Result = " << ten << endl; else cout << "Result = " << sum << endl; }
1 задание
#include<iostream>
#include<ctime>
using namespace std;
int main(){
srand(time(NULL));
int N, min = 10, range = 30;
int *arr;
cout << "enter size of arr(enter N) : ";
cin >> N;
arr = new int [N];
for(int i = 1; i <= N;i++)
arr[i] = rand()%(range + 1) + min;
cout << "arr : " << endl;
for(int i = 1; i <= N;i++)
cout << arr[i] << " " ;
cout << endl;
for(int i = 1; i <= N;i++){
if(arr[i] > 25)
arr[i] = i*i;
else
arr[i] = arr[i] + 5;
}
cout << "NEWarr : " << endl;
for(int i = 1; i <= N;i++)
cout << arr[i] << " " ;
}
2 задание
#include<iostream>
using namespace std;
int main(){
int N;
int *arr;
cout << "enter size of arr(enter N) : ";
cin >> N;
arr = new int [N];
for(int i = 1; i <= N;i++)
cin >> arr[i];
int temp = arr[1];
int templ = arr[N];
arr[1] = arr[2];
arr[2] = temp;
arr[N] = arr[N-1];
arr[N-1] = templ;
cout << "new arr : ";
for(int i = 1; i <= N;i++)
cout << arr[i] << " " ;
}
на С++ как то так
#include<iostream>
#include<ctime>
using namespace std;
int main(){
srand(time(NULL));
int N, a, sum = 0, ten = 10, index = 0;
int *arr;
cout << "enter size of arr(enter N) : ";
cin >> N;
arr = new int [N];
for(int i = 1; i <= N;i++)
arr[i] = rand()%25;
cout << "arr : " << endl;
for(int i = 1; i <= N;i++)
cout << arr[i] << " " ;
cout << endl;
cout << "enter a : " ;
cin >> a;
for(int i = 1; i <= N;i++)
{
if(arr[i] == a)
index = i;
}
if(index != 0)
{
for(int i = index + 1; i <= N;i++)
sum = sum + arr[i];
}
if(sum == 0)
cout << "Result = " << ten << endl;
else
cout << "Result = " << sum << endl;
}