Wednesday, May 13, 2015

Remove Vowels



#include<stdio.h>
int main()
{
        char a[]="rajkamal muthusamy";
        char *p,*q,*z;
        z=a;
        p=a;
        q=a;
        while(*p)
        {
                if(*p=='a' || *p=='e' || *p=='i' || *p=='o' || *p=='u')
                {
                        q=p+1;
                        while(*p)
                        {
                                *p=*q;
                                //printf("%s\t",p);
                                //printf("%s",z);
                                q++;
                                p++;
                        }
                 p=a;
                q=a;
                }
                p++;
        }

        printf("%s",z);
}


input:
rajkamal muthusamy
output:

rjkml mthsmy

character count





#include<stdio.h>
main()
{
        char p[]={"SOUMDsoundSDUTY"};
        char a[52]={0},*k,i;
        k=p;
        while(*k!='\0')
        {
                if((*k>='A')&&(*k<='Z'))
                        a[*k-65]=a[*k-65]+1;
                if((*k>='a')&&(*k<='z'))
                        a[*k-71]=a[*k-71]+1;
                if(*k==' '&&*k==',')
                        break;
                k++;
        }
//      for(i=0;i<52;i++)
//      {
//      printf("\n%d",a[i]);
//      }
        for(i=65;i<91;i++)
        {
                if(a[i-65]!=0)
                        printf("\n%c is repeated in %d times",i,a[i-65]);
        }
        for(i=97;i<123;i++)
        {
                if(a[i-71]!=0)
                        printf("\n%c is repeated in %d times",i,a[i-71]);
        }

}

find the string




#include<stdio.h>
void stricmp(char *p,char *q);
int strilen(char*s);
main()
{
        char a[]={"the"},b[]={"the cat sat the the on the mat"};
        printf("the word is %s",a);
        printf("\nthe setence is %s",b);
        stricmp(a,b);
}
            void stricmp(char *p,char *q)
{
        char *t;
        int k,times=0,c,i;
        t=p;
        k=strilen(q);
        for(i=1; i<=k; i++)
        {
                while((*p!='\0')&&(*q!=' '))
                {
                        if(*p==*q)
                        {
                                c=1;
                        }
                        else
                        {
                                c=0;
                        }
                        q++;
                        p++;
                }
                        if(c==1)
                        {
                                times++;
                        }
                        p=t;
                        q++;
                }
        printf("\nthe word repeated at %d times",times);
}
int strilen(char *s)
{
        int len=0;
        while(*s!=0)
{
                s++;
                len++;
        }
        return len;

}

str upper to lower



#include<stdio.h>
void convert(char *p);
main()
{
        char a[]={"KANCHANA KARTHIKA"};
        convert(a);
        printf("%s",a);
}
void convert(char *p)
{
        while(*p!='\0')
        {
                if(*p!=32)
                {
                        *p=*p+32;
                }
                p++;
        }

}

singlely Linked list



#include<stdio.h>
#include<stdlib.h>
struct list
{
        int data;
        struct list *next;
};
void addnode(int data);
void insert(int data,int count);
void deletefirst();
void deletemiddle(int count);
int length();
void deletelast(int count);
int getnth(int get);
void deletelist(int count);
void display();
struct list *head=NULL;
struct list *temp;
struct list *temp1;
void addnode(int data)
{

        temp=head;
        if(head==NULL)
        {
                head=(struct list *)malloc(sizeof(struct list));
                head->data=data;
                head->next=NULL;
                head=head;
        }
        else
        {
                while(temp->next!=NULL)
                {
                        temp=temp->next;
                }
                temp1=(struct list *)malloc(sizeof(struct list));
                temp1->data=data;
                temp1->next=NULL;
                temp->next=temp1;
        }
}
void insert(int data,int count)
{
//      struct list *temp;
        struct list *new;
        int i=1;
        temp=head;
        while(i<(count-1))
        {
                temp=temp->next;
                i++;
        }
        new=(struct list *)malloc(sizeof(struct list));
        new->data=data;
        new->next=temp->next;
        temp->next=new;
}
void deletefirst()
{

        temp=head;
        temp1=head;
        temp=temp->next;
        head=temp;
        free(temp1);
}
void deletemiddle(int count)
{
        int i=1;
        temp=head;
        temp1=head;
        while(i<count)
        {
                temp1=temp1->next;
                i++;
        }
        i=1;
        while(i<(count-1))
        {
                temp=temp->next;
                i++;
        }
        temp->next=temp1->next;
        free(temp1);
}
int length()
{
        int count=0;
        temp=head;
        while(temp!=NULL)
        {
                temp=temp->next;
                count++;
        }
        return count;
}
void deletelast(int count)
{
        int i=1;
        temp=head;
        temp1=head;
        while(i<count)
                {
                        temp1=temp1->next;
                        i++;
                }
        i=1;
        while(i<(count-1))
                {
                        temp=temp->next;
                        i++;
                }
        temp->next=NULL;
        free(temp1);

}
int getnth(int get)
{
        int i=1,q;
        temp=head;
        while(i<get)
        {
                temp=temp->next;
                i++;
        }
        q=temp->data;
        return q;
}
void deletelist(int count)
{
        int a,i=1;
        temp=head;
        temp1=head;
        while(i<count)
                {
                        temp1=temp1->next;
                        i++;
                }
        i=1;
        while(i<(count-1))
                {
                        temp=temp->next;
                        i++;
                }
        temp->next=NULL;
        free(temp1);
        a=count-1;
        if(a>0)
        {
        deletelist(a);
        }
        head=NULL;
}
void display()
{
        struct list *temp;
        temp=head;
        if(temp==NULL)
        {
        printf("No records found and cannot delete");
        return;
        }
        while(temp!=NULL)
        {
                printf("%d\n",temp->data);
                temp=temp->next;
        }
}
int main()
{
        int count,options,pos,q;
while(1)
        {
                printf("Press 1 for Insert node\n");
                printf("Press 2 for delete first node\n");
                printf("Press 3 for delete node\n");
                printf("Press 4 for delete last node\n");
                printf("Press 5 for get node\n");
                printf("press 6 for delete list\n");
                printf("Press 7 for display\n");
                printf("Press 8 for exit\n");
                scanf("%d",&options);
                switch(options)
                {

case 1:
                        printf("Enter the data:\n");
                        scanf("%d",&pos);
                        addnode(pos);
                        break;
case 2:
                        deletefirst();
                        break;
case 3:
                        printf("Enter the data:\n");
                        scanf("%d",&pos);
                        deletemiddle(pos);
                        break;
case 4:
                        count=length();
                        deletelast(count);
                        break;
case 5:
                        printf("Enter the data:\n");
                        scanf("%d",&pos);
                        q=getnth(pos);
                        break;
case 6:
                        count=length();
                        deletelist(count);
                        break;
case 7:
                        display();
                        break;
case 8:
                        printf("program terminated by user\n");
                        exit(0);
                        break;
default:
                        printf("please enter the valid option\n");
                        break;


                }
                printf("do you want to continue:Press Y to continue, Press N to exit\n");
                scanf(" %c",&options);
                if(options=='y')
                 continue;
                else
                {
                        printf("program terminated by user\n");
                        exit(0);
                }
        }

}

str replace



#include<stdio.h>
int main()
{
        char a[]="complete ref book";
        char b[]="ref";
        char c[]="hear";
        char *p,*q,*s,*t,*u,*r;
        p=a;
        q=b;
        r=c;
        u=p;
        s=a;
        int i=0,j=0,count=0,length=3,length1=4;
        while(*p)
        {
                while(*p==*q)
                {
                        p++;
                        q++;
                        count++;
                        if (count == length)
                        {
                                u=p;
                                if(length<length1)
                                {
                                        while(*p)
                                        {
                                                p++;
                                        }
                                        t=p+1;
                                        while(j<length1)
                                        {
                                                while(*p!='f')
                                                {
                                                        *t=*p;
                                                        t--;
                                                        p--;
                                                }
                                                j++;
                                        }
                                }
                                u=u-length;
                                while(i<length1)
                                                                     {
                                        *u=*r;
                                        r++;
                                        u++;
                                        i++;
                                }
                                r=c;
                        }
                }
                q=b;
                p++;
                count=0;
        }
        printf("%s",s);
}

str cmp using recursive



#include<stdio.h>
#include<string.h>
int compare(char *p,char*q,int l,int m);
int main()
{
        char a[]="deepan";
        char b[]="deepika";
        char *i,*j;
        int x=strlen(a),y=strlen(b),flag;
        i=a;
        j=b;
        flag=compare(i,j,x,y);
        if(flag==1)
                printf("the strings are same");
        else
                printf("the strings are different");
}
int compare(char *p,char *q,int l,int m)
{
        static int flag=0;
        if((*p==*q)&&(l==m))
        {
                p++;
                q++;
                compare(p,q,l--,m--);
                flag=1;
        }
        else
        {
                flag=0;
        }
        return flag;

}