Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save vlaleli/dd8dc625b37a1e7218d4e5b7a1b8e483 to your computer and use it in GitHub Desktop.
#include <iostream>
int main() {
const int SIZE = 17;
int arr[SIZE];
std::cout << "Enter 17 two-digit integers: ";
for (int i = 0; i < SIZE; ++i) {
std::cin >> arr[i];
if (arr[i] < 10 || arr[i] > 99) {
std::cerr << "Error: Number must be two digits." << std::endl;
return 1;
}
}
int totalSum = 0;
for (int i = 0; i < SIZE; ++i) {
int number = arr[i];
while (number > 0) {
totalSum += number % 10;
number /= 10;
}
}
std::cout << "Sum of array digits: " << totalSum << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment