Exercise 1.1 : Base and ASCII representation of character representation Print the decimal, octal and hexadecimal value of all characters between the start ad stop characters entered by a user. for example, if the user enters an ’A’ and ’H’, the program should print all the characters between ’A’ and ’H’ and their respective values in the different bases (decimal, octal, and hexadecimal) as follows ASCII Representation of D is 68 in Decimal 104 in Octal and 44 in Hexadecimal ASCII Representation of E is 69 in Decimal 105 in Octal and 45 in Hexadecimal ASCII Representation of F is 70 in Decimal 106 in Octal and 46 in Hexadecimal ASCII Representation of G is 71 in Decimal 107 in Octal and 47 in Hexadecimal ASCII Representation of H is 72 in Decimal 110 in Octal and 48 in Hexadecimal ASCII Representation of I is 73 in Decimal 111 in Octal and 49 in Hexadecimal ASCII Representation of J is 74 in Decimal 112 in Octal and 4A in Hex
#include <iostream>
using namespace std;
int main() {
char start, end;
cout << "Enter first character: ";
cin >> start;
cout << "Enter last character: ";
cin >> end;
for (char ch=start; ch<=end; ch++) {
int n = ch;
cout << "ASCII Representation of " << ch
<< " is " << dec << n << " in Decimal "
<< oct << n << " in Octal and "
<< hex << n << " in Hexadecimal" << endl;
}
return 0;
}
Comments
Leave a comment