Created
December 26, 2024 10:38
-
-
Save vlaleli/11937ccd60bd92e3a2ed06f55f51ae3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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