#include <iostream>
#include <time.h>
using namespace std;
int main(){
srand(time(0));
int A[20];
int sum = 0;
int index = 0;
cout << "Массив: { ";
for(int i = 0; i<20; i++){
A[i] = rand()%40-30;
cout << A[i] << " ";
}
cout << "}\n\n";
if(A[i]<=-5 and A[i]%4==0){
sum=sum+A[i];
index++;
cout << "Сумма: " << sum << endl;
cout << "Количество: " << index;
cout << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <time.h>
using namespace std;
int main(){
srand(time(0));
int A[20];
int sum = 0;
int index = 0;
cout << "Массив: { ";
for(int i = 0; i<20; i++){
A[i] = rand()%40-30;
cout << A[i] << " ";
}
cout << "}\n\n";
for(int i = 0; i<20; i++){
if(A[i]<=-5 and A[i]%4==0){
sum=sum+A[i];
index++;
}
}
cout << "Сумма: " << sum << endl;
cout << "Количество: " << index;
cout << endl;
return 0;
}
элементов, которые меньше -5 и номера которых кратны 4