In c++ char x[10]; x[0] = \'a\'; x[1] = \'b\'; x[2] = \'c\'; x[3] = \'d\'; x[4]
ID: 3834728 • Letter: I
Question
In c++
char x[10]; x[0] = 'a';
x[1] = 'b'; x[2] = 'c';
x[3] = 'd'; x[4] = 'e';
x[5] = 'f'; x[6] = 'g'; x[7] = 'h'; x[8] = 'i'; x[9] = 'j'; for (int i = 0; i<10; i++){ cout<< x[i]; // print each character cout << " "; }
cout << endl;
for (int i = 0; i<10; i++)
{ cout << (int)x[i]; // The actual data in x[0] is 97, the ascii code of ‘a’. cout << " "; }
cout<<(char)(x[0]-32); //’a’ is printed as ‘A’
in this code
using Ascii Table
When change these letter have to using Ascii Table
Explanation / Answer
#include<iostream.h>
void main(){
char input[10];
cout << "Enter String" << endl;
cin >> input;
for (int i = 0; i< 10; i++){
if ( (input[i] > 96) && (input[i] < 123 )){
input[i] = input[i] - 32;
}
if ( (input[i] > 64) && (input[i] < 91 )){
input[i] = input[i] + 32;
}
}
cout << input << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.