Einzelnen Beitrag anzeigen
Alt 21.06.08, 23:31   #36 (permalink)
Virus
 
Registriert seit: 16.11.06
Virus Leistung: Facit NTK
Virus eine Nachricht über ICQ schicken
Likes: 0
Standard

Hier noch meine Lösung in C++, ich hoffe sie funktioniert wie sie soll,
also die Beispiele bei wikipedia hab ich getestet die habn funktioniert.
Ist vielleicht nicht ganz so optimal programiert, aber ich bin für Verbesserungsvorschläge offen
C++   

Code:
 
#include <cstdlib>
#include <iostream>

using namespace std;

int umrechnung ( int dezimal );

int main(void)
{
    int dezimal;
    cout << "Hallo bitte geben sie die Zahl ein " << endl;
    if (!(cin >> dezimal)) {
              cout << "Falsche Eingabe! " << endl;
              system("pause");
              return 0;
              }
    umrechnung ( dezimal );
    system("pause");
    return 0;
}

int umrechnung( int dezimal ) {
    int var1=0;
    int array1[16] = {5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
    char array2[16][3] = { "A", "MA", "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };     
    for (int i=0;dezimal>0;) {
        if ( !((dezimal-array1[i])>-1) ) {
             i++;
             continue;
             }
        cout << array2[i];  
        dezimal = dezimal-array1[i];
        var1++;
        }
    cout << endl;
    return 0;
    }


Gruß Virus
Virus ist offline   Mit Zitat antworten
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61