An array of k characters is specified. Calculate the sum S first 20 negative elements of an array that are multiples of 5 . Remove from the array elements whose values are equal in absolute value to S
Here is the version of the program that performs the sum finding and searches for elements that are modulo S , but line 29 has no body after if , because I have no idea how to remove it from the array.
#include <iostream> #include <array> #include <cstdlib> using namespace std; int main(){ setlocale (0,"Rus"); int i,j=0,sum=0; const int k=40; array <int, k> arr={}; // Создается массив, все элементы которого инициализированы нулями for(i=0;i<k;i++){ arr[i]=-200+rand()%300; cout<<arr[i]<<endl; } for(i=0;i<k,j<20;i++){ if(arr[i]<0&&arr[i]%5==0) sum+=arr[i]; // Сумма 20 отрицательных элементов j++; } for(i=0;i<k;i++){ if(arr[i]==sum||arr[i]==-sum) // arr[i] } return 0; }
arraycontainer has a fixed size specified at compile time and does not support the delete operation. If you want to delete, usevector. - VTT