fork download
  1. #include <iostream>
  2. #include<cmath>
  3. #include <limits.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int einsen=0;
  10. int Eingabe=0;
  11. int i;
  12. const int bits_int = sizeof(int)*CHAR_BIT ;
  13. int feld[bits_int];
  14. cout<<"Geben Sie eine Zahl ein"<<endl;
  15. cin>>Eingabe;
  16. for (int i=bits_int-1; i >= 0; i--)
  17. {
  18. feld[i]=Eingabe%2;
  19. Eingabe/=2;
  20. }
  21. for(int i=0; i<bits_int;i++)
  22. {
  23. cout<<feld[i];
  24.  
  25. }
  26. if (feld[i]== 1)
  27. {
  28. ++einsen;
  29. cout<<" anzahl der einsen"<< einsen;
  30. }
  31.  
  32. return 0;
  33.  
  34. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Geben Sie eine Zahl ein
00000000000000000000000000000000