Skip to content

Instantly share code, notes, and snippets.

@batmantec
Created April 5, 2016 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmantec/3085ef3cb8ead203c68cf8f33abbcd85 to your computer and use it in GitHub Desktop.
Save batmantec/3085ef3cb8ead203c68cf8f33abbcd85 to your computer and use it in GitHub Desktop.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int checkMod3(int checkNum){
int work, ans;
work = checkNum%3;
if (work == 0){
ans = checkNum;
} else{
ans = 0;
}
return ans;
}
int main(){
int i = 0, exitLoop, forLoop, sum = 0;
cout << "Digit the total of number you will try: ";
cin >> i;
exitLoop = i;
int input[i], check[i];
for (i = 0; i != exitLoop; i++) {
cout << "Digit the number you want to try: ";
cin >> input[i];
check[i] = checkMod3(input[i]);
if (check[i] != 0){
sum = sum + check[i];
}
}
cout << "The numbers that where divisable by 3 are: ";
for (i = 0; i != exitLoop; i++) {
check[i] = checkMod3(input[i]);
if (check[i] != 0){
cout << check[i] << " ";
}
}
cout << endl;
cout << "The sum of the numbers that are divisible by 3 is: " << sum << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment