на С++ как то так
#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;
}
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] << " " ;
}
Поделитесь своими знаниями, ответьте на вопрос:
Напечатать числа следующим образом 25 25.5 24.8 26 26.5 25.8 . . 35 35.5 34.8 в паскале
begin
for i := 25 to 35 do
writeln(i, ' ', i + 0.5, ' ', i - 0.2);
end.