21.06.08, 23:31
|
#36 (permalink)
|
Registriert seit: 16.11.06 Likes: 0 | 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 |
| |