Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void bin(int temp)
- {
- int n,i=0,j,x,a[100];
- n=temp;
- while(n!=0)
- {
- x=n%2;
- n=n/2;
- a[i] = x;
- i++;
- }
- for(j=i-1; j>=0; j--)
- {
- cout << a[j];
- }
- cout << endl;
- }
- void octal(float temp)
- {
- int n,z,i=0,j,x,a[100],b[100];
- n=temp;
- float y = temp-n;
- while(n!=0)
- {
- x=n%8;
- n=n/8;
- a[i] = x;
- i++;
- }
- cout << "Integral: ";
- for(j=i-1; j>=0; j--)
- {
- cout << a[j];
- }
- int k=0;
- while(z!=8)
- {
- z = y*8;
- b[k] = z;
- y = y-z;
- k++;
- }
- cout << "Fraction: ";
- for(j=0; j<=k; j++)
- {
- cout << b[j];
- }
- cout << endl;
- }
- void hex(int temp)
- {
- int n,i=0,j,x,a[100];
- n=temp;
- while(n!=0)
- {
- x=n%16;
- n=n/16;
- a[i] = x;
- i++;
- }
- for(j=i-1; j>=0; j--)
- {
- if(a[j] == 10)
- cout << "A";
- else if(a[j] == 11)
- cout << "B";
- else if(a[j] == 12)
- cout << "C";
- else if(a[j] == 13)
- cout << "D";
- else if(a[j] == 14)
- cout << "E";
- else if(a[j] == 15)
- cout << "F";
- else
- cout << a[j];
- }
- cout << endl;
- }
- int main()
- {
- int op;
- float n;
- cout << "Decimal to non-decimal" << endl;
- while(1)
- {
- cout << "Enter option: ";
- cin >> op;
- if(op == 1)
- {
- cin >> n;
- cout << "Binary: "<< endl;
- bin(n);
- }
- if(op == 2)
- {
- cin >> n;
- cout << "Octal: "<< endl;
- octal(n);
- }
- if(op == 3)
- {
- cin >> n;
- cout << "Hexadecimal: "<< endl;
- hex(n);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement