Program to enter a letter and output the next 2 letters 1 Attachment(s) Program to enter a letter and output the next 2 letters #include #include void main() { clrscr(); char charac; cout << "Enter your letter : " << endl; cin>>charac; cout << "The 2 letters are : " << endl; cout << (char)(charac-1) << endl; cout << (char)(charac+1) << endl; getch(); } It then determines its previous letter and next letter and prints it out using the 'cout' command. Sample Input x Sample Output The next 2 letters after x are : y z |
Re: Program to enter a letter and output the next 2 letters But a good programmer will consider A-z & a-z as characters for a sequence. The code above will give "[" after Z and '{' after z ,although its a character but it dosnt make any sense . #include #include void main() { { clrscr(); //This clrscr produces wastege in systems performance char charac; cout << "Enter your char : " << endl; cin>>charac; cout << "The 2 letters are : " << endl; if (((char)(charac) <=90 && (char)(charac) >= 66 ) | (char)(charac) <=122 && (char)(charac) >= 98 )// this line can simply be replaced by if (charc != 'a' | charc!='A') cout << (char)(charac-1) << endl; else cout << "There is no char Before "<<(char)(charac)<< endl; if ((char)(charac) <=89 && (char)(charac) >= 65 | (char)(charac) <=121 && (char)(charac) >= 97 ) cout << (char)(charac+1) << endl; else cout << "There is no char After"<<(char)(charac)<< endl; getch(); }//end main function } |
Re: Program to enter a letter and output the next 2 letters Bahi jaan 1 program banay kay kafi ways hotay hain, yahain simple post kia hai. complex program k liyai acha programmer bhi chayai. and u can see that yeh 1st semester k liyai ha. Thanks for reply |
Re: Program to enter a letter and output the next 2 letters ur right, that wa meant for information..After all one has to cover all aspects :D |
All times are GMT +5. The time now is 08:00 PM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.