The code was given for a problem and you have to identitfy the logical error in it. That was simple. The code was to merge the Danagrams of 2 words. The danagram of a word is the letters of word arranged in sequential order. Eg danagram of abhinav is aabhinv. merging of danamagram is to merge the danagrams of 2 or more words such that the highest no of occurance are coming for each alphabet. Eg merging of aabhinv and abbhhixz is aabbhhinvxz.

Showing Answers 1 - 8 of 8 Answers

neenadgp

  • Mar 28th, 2008
 

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
    char str1[]="aabhinv";
    char str2[]="abbhinx";
    char ch,temp;
      //    int ch=65;
    int n=14;
    int len=0,i;
    clrscr();
    printf("n The original strings:nn");
    printf(" %s",str1);
    printf("nn %s",str2);
    printf("nn String after concatenation: ");
    strcat(str1,str2);
    printf("%s",str1);
    len=strlen(str1);
    printf("nnLength of the new string: %d",len);
    printf("nn Final String:");
    for(i=0;i<len;i++)
    {
        printf("n Pass %d:-n",i+1);
        for(int j=0;j<n-i-1;j++)
        {
            if(str1[j]>str1[j+1])
            {
                temp=str1[j];
                str1[j]=str1[j+1];
                str1[j+1]=temp;
            }
            printf(" %c",str1[j]);
        }

    }
    printf("nn");

    printf(" Sorted Data:-n");
    for(i=0;i<n;i++)
        printf(" %c",str1[i]);

    getch();
}

  Was this answer useful?  Yes

Kumar Shanu

  • Jan 20th, 2012
 

This code is the correct answer...try it urself...

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. #include<string.h>

  4. #include<stdlib.h>

  5. int main()

  6.  {

  7.  

  8.      char str1[50],str2[50],temp;

  9.     printf("enter 1st strings:");

  10.     gets(str1);

  11.  

  12.     int len=strlen(str1);

  13.     printf("

  14. Length of the string: %d",len);

  15.  

  16.     for(int i=0;i<len;i++)

  17. {

  18.  for(int j=i;j<len;j++)

  19.    {

  20.       if(str1[i]>=str1[j])

  21.       {

  22.  

  23.  

  24.           temp = str1[i];

  25.           str1[i]=str1[j];

  26.           str1[j]=temp;

  27.  

  28.       }

  29.    }

  30. }

  31. printf("

  32. new string:");

  33. puts(str1);

  34.  

  35. printf("

  36. enter 2nd string ");

  37.     gets(str2);

  38.     printf("

  39. String after concatenation: ");

  40.     strcat(str1,str2);

  41.     puts(str1);

  42.     len=strlen(str1);

  43.     printf("

  44. Length of the new string: %d",len);

  45.     printf("

  46. Final String:");

  47.     puts(str1);

  48. for(int i=0;i<len;i++)

  49. {

  50.  for(int j=i;j<len;j++)

  51.    {

  52.       if(str1[i]>=str1[j])

  53.       {

  54.  

  55.  

  56.           temp = str1[i];

  57.           str1[i]=str1[j];

  58.           str1[j]=temp;

  59.  

  60.       }

  61.    }

  62. }

  63. printf("

  64. new string:");

  65. puts(str1);

  66.  

  67. return 0;

  68.  }

  69.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions