Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- int main(void) {
- int zahl, i=1, zahl2, rest = 1;
- string oktalziffer[8] = {"0","1","2","3","4","5","6","7"};
- string oktal="", dual="";
- do { // negativ Eingaben abfangen
- cout << "Dezimalzahl = ? ";
- cin >> zahl;
- } while ( zahl < 0 );
- zahl2 = zahl;
- // Restwertmethode
- while ( zahl ) {
- rest = zahl % 8;
- zahl = zahl / 8;
- oktal = oktalziffer[rest] + oktal;
- } // while ( zahl ) {
- // Potenzenmethode
- for (i = 0; rest >= 0; i++) {
- rest = zahl2 - pow(2.,i);
- } // for (i = 0; rest >= 0; i++) {
- i--;
- for (;i>=0;i--) {
- rest = zahl2 - pow(2.,i);
- if ( rest >= 0 ) {
- if ( dual == "0" ) { dual = "1"; }
- else { dual = dual + "1"; }
- zahl2 = rest;
- } // if ( rest > 0 ) {
- else if ( rest < 0 ) {
- if ( dual == "0" ) { dual = "0"; }
- else { dual = dual + "0"; }
- } // else if ( rest < 0 ) {
- } //for (;i>=0;i--) {
- // Ausgaben
- cout << endl << endl;
- cout << "Umrechnung einer ganzzahligen, positiven Dezimalzahl in" << endl;
- cout << "- eine Dualzahl nach der Potenzenmethode : Dualzahl = " << dual << endl;
- cout << "- eine Oktalzahl nach der Restwertmethode: Oktalzahl = " << oktal << endl << endl << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment