//========================
//Program in C++ to learn to reverse a strings in Cpp, strrevcpp.cpp
//========================
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char orgstr[50];
char revstr[50];
char *p1,*p2;
cout<<"\n enter any string:\n";
cin>>orgstr;
cout<<"You entered: \n"<<orgstr;
p1=orgstr+strlen(orgstr)-1;
p2=revstr;
while(p1>=orgstr)
*p2++=*p1--;
*p2='\0';
cout<<"\n reversed string is: \n"<<revstr;
return 0;
}
//Program in C++ to learn to reverse a strings in Cpp, strrevcpp.cpp
//========================
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char orgstr[50];
char revstr[50];
char *p1,*p2;
cout<<"\n enter any string:\n";
cin>>orgstr;
cout<<"You entered: \n"<<orgstr;
p1=orgstr+strlen(orgstr)-1;
p2=revstr;
while(p1>=orgstr)
*p2++=*p1--;
*p2='\0';
cout<<"\n reversed string is: \n"<<revstr;
return 0;
}
No comments:
Post a Comment