Here is a C++ program to check whether the given two strings are anagram or not
SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
void sorte(char *str)
{
char temp;
int lenght=strlen(str);
for(int i=0;i<lenght-1;i++)
{
for(int j=0;j<lenght-1;j++)
{
if(str[j]>str[j+1])
{
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}
}
}
int main()
{
char str1[100],str2[100];
cout<<"Enter two Strings : ";
cin>>str1>>str2;
sorte(str1);
sorte(str2);
if(strcmp(str1,str2)==0)
cout<<"Two strings are anagram ";
else
cout<<"Two strings are not anagram ";
return 0;
}
#include<string.h>
using namespace std;
void sorte(char *str)
{
char temp;
int lenght=strlen(str);
for(int i=0;i<lenght-1;i++)
{
for(int j=0;j<lenght-1;j++)
{
if(str[j]>str[j+1])
{
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}
}
}
int main()
{
char str1[100],str2[100];
cout<<"Enter two Strings : ";
cin>>str1>>str2;
sorte(str1);
sorte(str2);
if(strcmp(str1,str2)==0)
cout<<"Two strings are anagram ";
else
cout<<"Two strings are not anagram ";
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment