C++ :: Aufgabe #1 :: Lösung #4
12 Lösungen

#1
Zeichen als Dezimal- bzw. Hexadezimalwert ausgeben
Anfänger - C++
von Gustl
- 12.08.2012 um 15:26 Uhr
Schreiben Sie ein Konsolenprogramm, das ein Zeichen einliest und dieses Zeichen sowohl
als Zeichen als auch als Dezimal- bzw. Hexadezimalwert ausgibt.
Verwenden Sie sowohl
als Zeichen als auch als Dezimal- bzw. Hexadezimalwert ausgibt.
Verwenden Sie sowohl
scanf
als auch cin
für die Eingabe, bei der Ausgabe probieren Siecout
und printf
aus.
#4

von Lex (20 Punkte)
- 01.12.2015 um 20:07 Uhr

#include <iostream> //for 'cout' and 'cin' #include <cstdio> //for 'printf' and 'scanf' int main() { char a,b; int int_b = 0; printf("Using 'printf' and 'scanf' from cstdio.\n"); printf("Please enter one character!\n"); scanf("%s", &a); printf("The corosponding decimal number is: %d\n", a); printf("The corosponding hexadecimal number is: %x\n\n", a); std::cout << "Using 'cout' and 'cin' from iostream.\n"; std::cout << "Please enter one character!\n"; std::cin >> b; int_b = static_cast<int>(b); std::cout << "The corosponding decimal number is: " << int_b << std::endl; std::cout << "The corosponding hexadecimal number is: " << std::hex << int_b << std::endl; return 0; }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1