/////////////////////////////////////////////////////////////////////
/* Mit diesem Programme m�chte ich
Dezimalzahlen in Zahlen des Bin�ren
Systems umwandeln und diese anschlie�end
ausgeben */
#include <stdio.h>
main () {
int zahl; ///
int bit = 0; /// Variablendeklaration der "zahl", des "bit" und der Z�hlvariable
"i"
int i = 0; ///
int a = 0;
fprintf(stderr,"Bitte geben sie eine positive Zahl ein, welche dann in das duale
Zahlensystem umgewandelt werden soll:\n"); /// Ausgabe
scanf("%d", &zahl); /// Einlesen auf Adresse &zahl
if(zahl > 2147483646){
printf("Die Zahl ist zu gro�!!!\n"); /// aussortieren zu gro�er Zahlen
}else{
if(zahl < 0){
printf("Ich sagte doch POSITIVE Zahl...\n"); /// aussortieren negativer
Zahlen
}else{
int lange = bestimme_laenge(zahl);
/// Initialisierung und Belegung von laenge mit dem R�ckgabewert der Funktion
"bestimme_laenge", der die Variable "zahl" �bergeben wird
int Dec[lange-1]; /// Initialisierung eines Array mit der L�nge lange
bzw. bis zur Stelle lange-1
printf("Die Zahl %d im dualen System ausgedr�ckt hei�t:\n", zahl);
while (zahl > 0){
bit = zahl % 2;
zahl = (zahl - bit) / 2;
Dec[i] = bit;
i++;
}
for(i = lange ; i >= 0; i--){
printf("%d",Dec[i]);
}
printf("\n");
}
}
}
bestimme_laenge(int zaal){
// int zaal;
int laenge = 0;
while (zaal > 0){
zaal = (zaal - (zaal % 2)) / 2;
laenge = laenge + 1;
}
printf("Die Bin�rzahl und somit das ben�tigte Array ist %d Stellen lang.\n",
laenge);
return laenge;
}
/////////////////////////////////////////////////////////////////
what the program is about:
you may input a decimal number and the program will convert it into a dual number...
after this it will determine the length of the dual number (bestimme_laenge() )
then it should declare an array Dec[] with last position --> lange-1
then the positions Dec[i] ... i++ were filled in while while()
after this it shut put out the positions of the array from Dec[lange] to Dec[0] so
that the dual number is in the right order...
but there are more numbers in the output the array shoul be long... o.O thats what i
don't understand...
i hope you can help me with this prob...
greetz
DaRkI
sorry, my english is bad.. i know... but I hope you'll understand what i mean ;)
--
60% Onlinekosten sparen!
Jetzt Premium Mitglied bei freenet.de werden und mit dem
Tarifnavigator guenstiger surfen.
http://www.freenet.de/tipp/premium/tarif/index.html
_______________________________________________
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech