Skip to content

Instantly share code, notes, and snippets.

@Zulcom
Created September 24, 2017 13:23
Show Gist options
  • Save Zulcom/c2d970586091981e7a86cd06827c8f70 to your computer and use it in GitHub Desktop.
Save Zulcom/c2d970586091981e7a86cd06827c8f70 to your computer and use it in GitHub Desktop.
Задан одномерный массив A[1..18]. Сформировать новый массив B[1..18], элементы которого определяются так: B[i]= a[1]+a[2]+...+a[i]. Найти сумму чётных элементов массива В.
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int masA[18];
int masB[18];
for(int i = 0; i < 18; i++)
{
masA[i] = i+1;
cout << masA[i] << " ";
}
cout << endl;
int oddsum = 0;
masB[0] = masA[0];
cout << masB[0] << " ";
for(int i = 1; i < 18; i++)
{
masB[i] = masB[i-1] + masA[i];
if(masB[i] % 2 == 0) oddsum += masB[i];
cout << masB[i] << " ";
}
cout << endl <<" Odd Sum in b array: " << oddsum <<endl;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment