Monday, 24 March 2014

write a program to check two string are anagram or not.

/////////////////////////////////////////////////////////////definition//////////////////////////////////////////////////////////////////////////////////
what is anagram ?
ans. when  letter in two word is of same type even position is different and letters are uppercase or lowercase then these words are called as anagram.eg 
ist word :CproGRAM
2nd word:cmargPOR
these words are anagram .

/////////////////////////////////////////////////////////////////hint/////////////////////////////////////////////////////////////////////////////////////

/* write a program for anagram
   hint: first remove the integer from  both string
         second convert the both string either uppercase or lowercase
         third sort the both string alphabetically 
         fourth and last compare both string by strcmp if both string equal then anagram otherwise not anagram */
/////////////////////////////////////////////////////////program//////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<string.h>
int i,j,n1,n2,n3,n4;
char temp[90]={0},temp1[90]={0};
char s1[90],s2[90],ch=0,ch1=0,*p1,*p2;
main()
{
puts("enter first string:");
scanf(" %[^\n]s",s1);
puts("enter second string:");
scanf(" %[^\n]s",s2);
n1=strlen(s1);
n2=strlen(s2);
j=0;
for(i=0;i<n1;i++)
 {
  if(!(s1[i]>=48 && s1[i]<=57))
{     
temp[j]=s1[i];
 j++;
   }
}
 temp[j]='\0';
j=0;
for(i=0;i<n2;i++)
 {
  if(!(s2[i]>=48 && s2[i]<=57))
{     
temp1[j]=s2[i];
 j++;
   }
}
 temp1[j]='\0';
n3=strlen(temp);
 for(i=0;i<n3;i++)
{
 if(temp[i]>=97 && temp[i]<=122)
 {
  temp[i]=temp[i]-32;
 }
}
n4=strlen(temp1);
for(i=0;i<n4;i++)
{
 if(temp1[i]>=97 && temp1[i]<=122)
  {
   temp1[i]=temp1[i]-32;
}
}
p1=temp;
for(i=n3-1;i>0;i--)
 {
  for(j=0;j<i;j++)
   {
     if(p1[j]>p1[j+1])
     {
     ch=p1[j];
   p1[j]=p1[j+1];
   p1[j+1]=ch;
    }
  }
 }
for(i=n4-1;i>0;i--)
 {
  for(j=0;j<i;j++)
   {
     if(temp1[j]>temp1[j+1])
     {
     ch1=temp1[j];
   temp1[j]=temp1[j+1];
   temp1[j+1]=ch1;
    }
  }
 }
if((strcmp(p1,temp1)==0))
  {
   printf("ANAGRAM\n");
  }
  else
{
  printf("NOT ANAGRAM\n");
 }

}//main

write a program to sort a number in increasing order using bubble sort.


#include<stdio.h>
main()
{
int a[5];
int i,n,j;
printf("enter five nuber:");
for(i=0;i<5;i++)
{
 scanf("%d",&a[i]);
}
for(i=5-1;i>0;i--)
   {
    for(j=0;j<i;j++)
    {
       if(a[j]>a[j+1])
       {
         n=a[j];
       a[j]=a[j+1];
      a[j+1]=n;
      }
  }
}
for(i=0;i<5;i++)
 {
 printf("%d\t",a[i]);
}
}

write a program to reverse a string.


#include<stdio.h>
#include<string.h>
main()
{
char s[90],temp;
int n,i,j;
printf("enter the string:");
scanf(" %[^\n]s",s);
n=strlen(s);
for(i=0,j=n-1;i<j;i++,j--)
 {
 temp=s[j];
  s[j]=s[i];
  s[i]=temp;
 }
printf("%s",s);
}

write a program for table.


#include<stdio.h>
main()
{
int n,i,sum=0;
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=10;i++)
 {
  sum=n*i;
 printf("%d\n",sum); 
}
}

Contact Form

Name

Email *

Message *