Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int prime = 0, nonPrime = 0;
- string command;
- cin >> command;
- while (command != "stop") {
- int number = stoi(command);
- if (number >= 0) {
- if (number % 2 == 0 || number % 3 == 0 || number % 5 == 0) {
- if (number == 2 || number == 3 || number == 5 || number == 7) {
- prime += number;
- }
- else {
- nonPrime += number;
- }
- }
- else {
- prime += number;
- }
- }
- else {
- cout << "Number is negative.\n";
- }
- cin >> command;
- }
- cout << "Sum of all prime numbers is: " << prime << endl;
- cout << "Sum of all non prime numbers is: " << nonPrime << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement