Advertisement
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;
- bool prime = true;
- int sumPrime = 0;
- int sumNonPrime =0;
- int number;
- while (input != "stop" && input != "STOP"){
- int number = stoi (input);
- if (number < 0){
- cout << "Number is negative." << endl;
- cin >> input;
- continue;
- }
- for(int i = 2; i <= number /2; ++i)
- {
- if(number % i == 0)
- {
- prime = false;
- break;
- }
- }
- if (prime){
- sumPrime += number;
- } else {
- sumNonPrime += number;
- prime = true;
- }
- cin >> input;
- }
- cout << "Sum of all prime numbers is: " << sumPrime << endl;
- cout << "Sum of all non prime numbers is: " << sumNonPrime << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement