fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. size_t oddcount(const string &s)
  5. {
  6. size_t count=0;
  7. for(char ch:s) count+=ch&1;
  8. return count;
  9. }
  10.  
  11. int main()
  12. {
  13. cout<<"Podaj liczbe: ";
  14. string value;
  15. cin>>value;
  16. size_t odd=oddcount(value);
  17. cout<<"Liczba zawiera"<<endl;
  18. cout<<"Cyfr parzystych: "<<value.size()-odd<<endl;
  19. cout<<"Cyfr nieparzystych: "<<odd<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3464KB
stdin
1234579
stdout
Podaj liczbe: Liczba zawiera
Cyfr parzystych: 2
Cyfr nieparzystych: 5