Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<math.h>
- #include<stdio.h>
- #include<string.h>
- #include<conio.h>
- #include<vcl.h>
- void main()
- {
- char a[33],antwort='j';
- int auswahl;
- long dez;
- void DeztoDual(long,char *);
- while(antwort=='j')
- {
- printf(" Umwandlungen von Dezi in Dualzahlen\n");
- printf(" (1) Dezimalzahl-Dualzahl\n");
- /* Wenn Menü erwünscht wird1!
- do
- {
- cout <<(" Bitte entsprechende Zahl für da Menü(1,2,3,4,5)auswählen: ");
- cin >> auswahl;
- if(auswahl != 1) cout <<("\n Falsche Eingabe!");
- }
- while(auswahl!=1);
- */
- clrscr();
- if(true) //Wenn Menü erwünscht wird dann(auswahl=1)
- {
- cout <<(" Umrechnung Dezimalzahl in Dualzahl\n");
- cout <<(" Ergebnis beschränkt auf 32 Stellen!\n\n");
- cout <<(" Dezimalzahl: ");
- cin >> dez;
- DeztoDual(dez,a);
- cout << " Dualzahl: " << a;
- }
- cout << ("\n\n\n Noch einmal (j/n)? ");
- cin >> antwort;
- cout <<("\n\n");
- clrscr();
- }
- }
- void DeztoDual(long dez,char a[])
- {
- char zeichenlaenge[33]; long result;
- a[0]='\0';
- while(dez>0)
- {
- result=dez%2;
- if(result==1)
- {
- strcpy(zeichenlaenge,"1"); //Kopieren eines Strings
- }
- else
- {
- strcpy(zeichenlaenge,"0");
- }
- strcat(zeichenlaenge,a); //strcat hängt an das Ende von dem Ziel
- //eine Kopie von der Quelle an.
- strcpy(a,zeichenlaenge);
- dez/=2;
- }
- }
Add Comment
Please, Sign In to add comment