#include<iostream>
#include<cstring>
#define SIZE 50
usingnamespacestd;inti,top=-1;charstack[SIZE];boolpush(charelement){if(top==(SIZE-1)){cout<<"\nStack overflow";returnfalse;}else{stack[++top]=element;returntrue;}}charpop(){if(top==-1){cout<<"\nStack underflow";return0;}else{returnstack[top--];}}intmain(){cout<<"———————————————————————————————————————————";cout<<"\nProgram to reverse a given string";cout<<"\n———————————————————————————————————————————";chars[50];cout<<"\nEnter the string ";cin>>s;for(i=0;i<strlen(s);i++){push(s[i]);}for(i=0;i<strlen(s);i++){s[i]=pop();}cout<<"\nThe reverse string is "<<s;cout<<"\n———————————————————————————————————————————\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to reverse a given string
———————————————————————————————————————————
Enter the string KODINGWINDOW
The reverse string is WODNIWGNIDOK
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.