ASCII code chart.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

ASCII code chart..

I wrote this code..to show ASCII code, their hex value, and the symbol associated with it...but sololearn compiler shows (Time out)..before even executing full code..i think maybe its a slow algorithm ..can someone suggest a faster algorithm..for this.. CODE>> #include <iostream> using namespace std; int main() { int a[127]; // an array of 128 elements for (int i=0;i<128;i++) //loop { cout<<" For ("<<i<<") : "; cout<<"Hex "<<"= " ; std::cout.setf(std::ios::hex); cout<<hex<<" "<<i<<" " ; std::cout.unsetf(std::ios::hex); cout<<"Character: "<<(char) i; /* i have included (char) to change data type into character..*/ if(i<33) cout<<"null"<<endl; //i added this becoz it does not have symbol upto ASCII code 33 else cout<<endl; } return 0; }

1st Oct 2017, 1:40 PM
Omkar Tripathi
Omkar Tripathi - avatar
4 Answers
+ 15
There's no serious problem in your code. int a[127]; is an unsed array. It seems that you copy and pase that "std::cout.setf(std::ios::hex);" from somewhere ! (That's not a problem but you forgot to remove excess std::) #include <iostream> using namespace std; int main() { for (int i=0;i<128;i++) { cout<<" For ("<<i<<") : "; cout<<"Hex "<<"= " ; cout.setf(ios::hex); cout<<hex<<" "<<i<<" " ; cout.unsetf(ios::hex); cout<<"Character: "<<(char)i; /* i have included (char) to change data type into character..*/ if(i < 33) cout<<"null"<<endl; //i added this becoz it does not have symbol upto ASCII code 33 else cout<<endl; } } for time out problem see [https://www.sololearn.com/Discuss/754927/what-does-it-meamt-time-limit-exceding-in-c]
1st Oct 2017, 2:43 PM
Babak
Babak - avatar
+ 12
My ad-hoc solution to overcoming this barrier! I described the problem inside the code. https://code.sololearn.com/cr2X3H0DHY02
2nd Oct 2017, 5:34 AM
Babak
Babak - avatar
+ 10
Good job Aryan. Limitations always make us smarter! ;)
2nd Oct 2017, 10:31 AM
Babak
Babak - avatar
+ 4
@Babak Sheykhan Your way is really smart...i just made a few more changes..i removed the extra space in cout..and changed (else if) to if..becoz that part must be executed for every odd no. now the code is... https://code.sololearn.com/cGrhpJlYZq6z
2nd Oct 2017, 10:21 AM
Omkar Tripathi
Omkar Tripathi - avatar