Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define NUMBERS_COUNT 10
- /**
- * Function which determines whether or not is one number divisible by another.
- *
- * @param dividend Number we want to know if is divisible.
- * @param divisor Number by which we want to examine divisibility.
- * @return Returns true if is divisible otherwise false.
- */
- bool isDivisibleBy ( int dividend, int divisor )
- {
- return ! ( dividend % divisor );
- }
- /**
- * Program which asks for ten numbers and then prints sum of which of them are divisible by 3, 5 and 7.
- *
- * @return Returns 1 if wrong input is detected, 0 if everything ok.
- * @author Michael Hartman [email protected]
- */
- int main ( int argc, char ** argv )
- {
- std::cout << "Enter 10 numbers: ";
- int divisibleBy3 = 0, divisibleBy5 = 0, divisibleBy7 = 0, tmp;
- for ( int i = 0; i < NUMBERS_COUNT; ++ i )
- {
- if ( ! ( std::cin >> tmp ) )
- {
- std::cerr << "Wrong input!" << std::endl;
- return 1;
- }
- if ( isDivisibleBy ( tmp, 3 ) )
- divisibleBy3 += tmp;
- if ( isDivisibleBy ( tmp, 5 ) )
- divisibleBy5 += tmp;
- if ( isDivisibleBy ( tmp, 7 ) )
- divisibleBy7 += tmp;
- }
- std::cout << "soucet delitelnych tremi = " << divisibleBy3 << std::endl;
- std::cout << "soucet delitelnych peti = " << divisibleBy5 << std::endl;
- std::cout << "soucet delitelnych sedmi = " << divisibleBy7 << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment