Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int main () {
- string input;
- cin >> input;
- int prime = 0;
- int nonPrime = 0;
- while(input != "stop") {
- int number = stoi(input);
- if(number >= 0) {
- bool isPrime = true;
- for(int i = 2; i <= number / 2; ++i) {
- if(number % i == 0) {
- isPrime = false;
- break;
- }
- }
- if(isPrime) {
- prime += number;
- } else {
- nonPrime += number;
- }
- } else {
- cout << "Number is negative." << endl;
- }
- cin >> input;
- }
- 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