Saturday, September 27, 2008

String Question Answer

  • Problem Defination: Delete the duplicate character from the string and print the new string
-----------------------------------------------------------------------------------------------------------------------------------------------
  • Sample I/O: Input: ramshekhar
Output: ramshekr
------------------------------------------------------------------------------------------------------------------------------------------------
  • Algorithm :
void newstring(char *,int *);
void print(char *,int *);
start
var i,size,str[20]; //variable name
Print "enter a string";
Scan str; //enter the string
size=strlen(str); //size of string
newstring(str,&size); //call the newstring function
print(str,&size); //call the print function
End
void newstring(char *p,int *size)
{
int i,j,k; //variablename
for(i=0;i<*size;i++)
{
for(j=i;j<*size;j++)
{
if(*(p+i)==*(p+j+1)) //condition checking
{
for(k=j;k<*size;k++)
{
*(p+k+1)=*(p+k+2); //delete the duplicate character
}
*size=*size-1; // size decrease
}
}
}
}
void print(char *p,int *size)
{
int i;
printf("string after removing duplicate character is\n");
for(i=0;i<*size;i++)
{
printf("%c",*(p+i)); //print the new string charcter
}
} ------------------------------------------------------------------------------------------------------------------------------------------------ Pritesh Jindal
M080363CA