Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- main() {
- int sumPrime = 0;
- int sumNoPrime = 0;
- string command;
- cin >> command;
- int number = 0;
- while (command != "stop" && command != "STOP") {
- number = stoi(command);
- bool flag = false;
- if (number < 0) {
- cout << "Number is negative." << endl;
- }
- for (int i = 2; i <= number / 2; ++i) {
- if (number % i == 0) {
- sumNoPrime += number;
- flag = true;
- break;
- }
- }
- if (flag == false && number >= 2) {
- sumPrime += number;
- }
- cin >> command;
- }
- cout << "Sum of all prime numbers is: " << sumPrime << endl;
- cout << "Sum of all non prime numbers is: " << sumNoPrime << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement