Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. bool czy2(string a){
  8.     int b=0,c=0,d=0,e;
  9.     for(int i=a.length();i>0;i--){
  10.     e=(int)a[i]-48;
  11.     c=c+(e*pow(2,b));
  12.     b++;
  13.     }
  14.     if(c%2==0) return true;
  15.     else return false;
  16. }
  17. bool czy8(string a){
  18.     int b=0,c=0,d=0,e;
  19.     for(int i=a.length();i>0;i--){
  20.     e=(int)a[i]-48;
  21.     c=c+(e*pow(2,b));
  22.     b++;
  23.     }
  24.     if(c%8==0) return true;
  25.     else return false;
  26. }
  27.  
  28. int main(){
  29.     ifstream odczyt("liczby.txt");
  30.     string a;
  31.     int e=0,f=0;
  32.     for(int i=0;i<1000;i++){
  33.         odczyt>>a;
  34.         if(czy2(a)==true) e++;
  35.         if(czy8(a)==true) f++;
  36.     }
  37.     cout<<e<<endl<<f;
  38.     system("PAUSE");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement