10 Answers
New AnswerThis could be done by creating two char arrays that consist of alphabet and backward alphabet respectively. But i am searching for pre defined function to do this as creating two char arrays of 26 elements each would be time consuming plus inefficient.
5/17/2022 5:34:27 AM
Manav Roy10 Answers
New AnswerYou can just do something like cin >> ch; ch = toupper(ch);//#<cctype> cout <<(char) ('Z'-(ch-'A'))<< endl;
Wdym by its corresponding one ? You state having one backward so like {A,B,C } {C,B,A } ??
All chars have an associated decimal number (ascii table ) (ch -‘A’) -> ch - 65 Basically how far from 65 am I => disp (‘Z‘- disp ) -> 90 - disp From 90 take away the disp (char) cast back to a character
Manav Roy You could create 1 alphabet consisting of 26 letters with string indexes ranging from 0 to 25 IE: A = 0, Z = 25 In order to get the reverse letter, you can use 25 - index of letter IE: A = 0. 25 - 0 = 25 = Z D = 3. 25 - 3 = 22 = V Y = 24. 25 - 24 = 1 = B Of course, you could use different alphabets
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message