Code:
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { clrscr(); char first[10], second[10]; int ctr,ctr2,ctr3,len1,len2,word=0,count=0,larger=0; int tae1,tae2; cout<<"Enter the first word:"; scanf("%s",&first); cout<<"Enter the second word:"; scanf("%s",&second); len1 = strlen(first); len2 = strlen(second); tae1=len1-1; tae2=len2-1; for(ctr=0;ctr==tae1;ctr++) { for(ctr2=0;ctr2==tae2;ctr2++) { if(strcmp(&first[ctr],&second[ctr2])); { second[ctr2]='\0'; word++; } } if(word>=2) { for(ctr3=0;ctr3==tae1;ctr3++) { if(!strcmp(&first[ctr],&first[ctr3])) { larger++; } } if(word>larger) { cout<<"The first word is NOT"; break; } else if(word<=larger) { word=0; count++; } } if(word==1) { word=0; count++; } } if (count==tae2) { cout<<"The second word is anagram of the first word"; } else { cout<<"The second word is not an anagram of the first word"; } cout<<word; cout<<second[1]; getch(); }
how do we make it work?
Comment