#include <iostream.h>
#include <conio.h>
#include<stdio.h>#include<string.h>
void main()
{
int str[50], rev[50];
cout<< "\n Enter a string :";
gets(str);
int l = strlen(str);
/* Reverse String using another array */
for( int i = l-1, k = 0 ; i>= 0 ; i--, k++)
rev[k] = str[i];
rev[k] = '\0';
cout<< "\n Original String is "<< str;
cout<< "\n Reverse String is "<< rev ;
cout<< "\n Reverse String is ";
/* Reverse String without using another array */
for( i = l-1 ; i>=0 ; i--)
cout<< str[i];
getch();
}
#include
ReplyDelete#include
#include
void main()
{
char a[40],b[40];
int i,l;
cout<<"\nenter ur string";
gets(a);
l=strlen(a);
for(i=0;i<l;i++)
{
b[i]=a[l-(i+1)];
}
for(i=0;i<l;i++)
{
cout<<b[i];
}}
Here is a c program to : Reverse a string using pointers and recursion
ReplyDelete