Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- struct bin
- {
- bin * next;
- int v;
- };
- void Input(bin * w, int num)
- {
- w->next = new bin;
- w->next->v = num;
- w->next->next = NULL;
- }
- void Output(bin * temp)
- {
- if(temp->next != NULL)
- {
- Output(temp->next);
- }
- if(temp->v != 2)
- {
- cout<<temp->v;
- }
- }
- void MidSix(bin * temp, int mas[6])
- {
- int sum = 0;
- bin * o;
- o = temp;
- while(o->next != NULL)
- {
- sum ++;
- o = o->next;
- }
- sum = (sum - 6) / 2;
- while(sum > 0)
- {
- temp = temp->next;
- sum --;
- }
- while(sum < 6)
- {
- temp = temp->next;
- mas[5 - sum] = temp->v;
- sum ++;
- }
- sum=0;
- cout<<"\nMid:";
- int y=0;
- while(sum<6)
- {
- cout<<mas[sum];
- if(mas[sum] == 1)
- {
- y = y + pow(2,sum);
- }
- sum++;
- }
- for (int e = 0; e < 6; e ++)
- {
- if(mas [5-e] == 1)
- {
- y = y + pow(2,e);
- }
- }
- cout<<"\nDec:"<< y ;
- }
- int main()
- {
- int mas[6];
- bin u, * q, *y;
- q = &u;
- y = &u;
- q->v = 2;
- char end;
- int num, x;
- num = 100;
- do
- {
- x = num % 2;
- Input (q,x);
- q = q->next;
- if(x == 1){num - 1;}
- if(num != 1)
- {
- num = num / 2;
- }
- else{ end = 'Y';}
- }while(end != 'Y');
- cout<<"\nBin:";
- Output(y);
- cout<<"\n";
- MidSix(y->next, mas);
- cout<<"\n\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement