Advertisement
Guest User

Untitled

a guest
Sep 1st, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. main () {
  8.  
  9.     int sumPrime=0;
  10.     int sumNoPrime=0;
  11.  
  12.     string command;
  13.     cin>>command;
  14.  
  15.     int number=0;
  16.  
  17.  
  18.     while(command!="stop"){
  19.  
  20.         number=stoi(command);
  21.         bool flag=false;
  22.  
  23.             if(number<0){
  24.                 cout<<"Number is negative."<<endl;
  25.             }
  26.  
  27.             for(int i = 2; i <= number / 2; ++i){
  28.                     if(number % i == 0){
  29.                         sumNoPrime+=number;
  30.                         flag=true;
  31.                         break;
  32.                     }
  33.  
  34.             }
  35.             if(flag==false && number>=2){
  36.                 sumPrime+=number;
  37.             }
  38.  
  39.  
  40.         cin>>command;
  41.  
  42.     }
  43.     if(command=="stop"){
  44.         cout<<"Sum of all prime numbers is: "<<sumPrime<<endl;
  45.         cout<<"Sum of all non prime numbers is: "<<sumNoPrime<<endl;
  46.     }
  47.  
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement