Дан одномерный массив A[19]. НА си++
помогите пожалуйста хотя бы одну программку помогите решить
Задача 1.
Найдите максимальный элемент массива из элементов, стоящих на местах, номера которых кратны пяти.
Задача 2.
Замените отрицательные элементы, стоящие на нечётных местах на последний элемент массива.
Ответы
1)Задание:
#include <iostream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main(){
setlocale(LC_ALL, "Russian");
int Indexmax=0;
srand(time (NULL));
int max = 0;
const int N=19;
int array[N];
int i;
for(i=0;i<N;i++)
{
array[i]=rand()%50;
cout<< setw(5) <<array[i];
}
cout << endl;
for(i=0;i<N;i++)
{
if(array[i]>max && array[i] % 5 == 0)
{
max=array[i];
}
}
cout << endl;
if(max)
cout<<"max=" << max << endl;
else
cout << "Чётных нету";
return 0;
}
2) Задание:
#include <iostream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main(){
setlocale(LC_ALL, "Russian");
int last2 ;
int last;
srand(time (NULL));
const int N=19;
int array[N];
int i;
cout<< "До замены: " << endl;
for(i=0;i<N;i++)
{
array[i]=rand()%50 - 10;
cout<< setw(5) <<array[i];
}
cout << endl;
for(i=0;i<N;i++)
{
if(array[i]>0)
{
last = array[i];
}
}
cout<<"После замены: " << endl;
for(i=0;i<N;i++)
{
if(array[i]<0)
{
array[i]=last;
}
cout<< setw(5) <<array[i];
}
cout << endl;
cout << "Последнее число массива: "<< last;
return 0;
}