Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created December 26, 2024 10:38
Show Gist options
  • Select an option

  • Save vlaleli/11937ccd60bd92e3a2ed06f55f51ae3a to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/11937ccd60bd92e3a2ed06f55f51ae3a to your computer and use it in GitHub Desktop.
#include <iostream>
int main() {
const int SIZE = 10;
int arr[SIZE];
std::cout << "Enter 10 integers: ";
for (int i = 0; i < SIZE; ++i) {
std::cin >> arr[i];
}
int sum = 0;
int count = 0;
for (int i = 0; i < SIZE; ++i) {
if (arr[i] < 0) {
break;
}
sum += arr[i];
++count;
}
std::cout << "Sum of elements up to the first negative number: " << sum << std::endl;
std::cout << "Number of elements up to the first negative number: " << count << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment