Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //dane: https://pastebin.com/qpb9EhWb
- #include <fstream>
- #include <math.h>
- #include <string>
- using namespace std;
- int main() {
- ifstream IN("liczby.txt");
- string bin;
- int size, dec, parzyste=0, max=0, cyfr9=0;
- while (IN >> bin) {
- size = bin.length();
- dec = 0;
- if (size == 9) {
- cyfr9++;
- }
- if (bin[size - 1] == '0') {
- parzyste++;
- }
- for (int i = 0; i < size; i++) {
- if (bin[size - 1 - i] == '1') {
- dec += pow(2, i);
- }
- }
- max = dec > max ? dec : max;
- }
- cout << "Liczba parzystych liczb to: " <<parzyste<< endl;
- cout << "Najwieksza liczba to: " << max << "(10), ";
- int max_bin = max;
- while (max_bin != 0) {
- cout << max_bin % 2;
- max_bin = (max_bin - max_bin % 2) / 2;
- }
- cout << "(2)" << endl;
- cout << "Ilosc 9-cyfrowych liczb to: " << cyfr9 << "(10), ";
- while (cyfr9 != 0) {
- cout << cyfr9 % 2;
- cyfr9 = (cyfr9 - cyfr9 % 2) / 2;
- }
- cout << "(2)" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment