ds file original

Embed Size (px)

Citation preview

  • 8/7/2019 ds file original

    1/16

    'DWD

    6WUXFWXUHV

    3URJUDPILOH

    Submitted by :JaskarandeepPunia

    Roll No. : 10901140

  • 8/7/2019 ds file original

    2/16

    Class :B.Tech 2nd

    year , 3rd

    Semester

    Group : CE-4

    Programe to detemine whether given string is pallindromeor not.

    #include

    #include

    void main()

    {

    char s[999],t[999];

    clrscr();

    printf("enter the string\t");

    scanf("%s",&s);

    strcpy(t,s);

    strrev(t);

    if(strcmp(s,t)==0)

    {

    printf("pallindrome");

    }

    else

  • 8/7/2019 ds file original

    3/16

    printf("non pallindrome");

    getch();

    }

    OUTPUT :

    y Case 1.enter the string madam

    pallindrome

    y Case 2.enter the string jaskaran

    nonpallindrome

  • 8/7/2019 ds file original

    4/16

    Programe for Linear Search in array.#include

    #include

    #include

    void main()

    {

    intn,i,item,a[100];

    clrscr();

    printf("enter the no. of elements of array");

    scanf("%d",&n);

    printf("\n enter the elements of array");

    for(i=0;i

  • 8/7/2019 ds file original

    5/16

    scanf("%d",&item);

    for(i=0;i

  • 8/7/2019 ds file original

    6/16

    4

    enter the item 3

    item is found at location =3

    Program for inserting element in a linear array.#include

    #include

    #include

    void main()

    {

    intn,k,a[100]={1,2,3,4},i,item;

    clrscr();

    printf("\n enter the no of elements of array");

    scanf("%d",&n);

    printf("enter the location k");

    scanf("%d",&k);for(i=n;i>=k;i--)

    {

    a[i+1]=a[i];

    }

    printf("\n enter the item");

    scanf("%d",&item);

    a[k]=item;n=n+1;

    printf("array is");

    for(i=0;i

  • 8/7/2019 ds file original

    7/16

    printf("\n a[%d]=%d",i,a[i]);

    }

    getch();

    }OUTPUT :

    enter the no of elements of array 5

    enter the location k 2

    enter the item 9

    array is

    a[0]=1

    a[0]=2

    a[0]=9

    a[0]=3

    a[0]=4

    a[0]=0

    a[0]=0

  • 8/7/2019 ds file original

    8/16

    Program for deleting element from linear array.#include

    #include

    #include

    void main()

    {

    intn,k,a[100]={1,2,3,4},i,item;clrscr();

    printf("\n enter the no of elements of array");

    scanf("%d",&n);

    printf("enter the location k");

    scanf("%d",&k);

    item=a[k];

    for(i=k;i

  • 8/7/2019 ds file original

    9/16

    OUTPUT :enter the no of array 6

    enter the location 2

    array is

    a[0]=1

    a[0]=2

    a[0]=4

    a[0]=0

    a[0]=0

    a[0]=0

  • 8/7/2019 ds file original

    10/16

    Program for sorting elements of an array (Bubble Sort)#include

    #include

    #include

    void main()

    {

    int a[100],n,i,ptr,d;clrscr();

    printf("enter the no. of elements");

    scanf("%d",&n);

    printf("\n enter the array");

    for(i=0;i

  • 8/7/2019 ds file original

    11/16

    }

    ptr=ptr+1;

    }

    }printf("\n array is");

    for(i=0;i

  • 8/7/2019 ds file original

    12/16

    Program for Binary Search in array.#include

    #include

    #include

    void main()

    {

    intbeg,n,end,mid,i,item,a[100];

    clrscr();printf("enter the no. of elements of array");

    scanf("%d",&n);

    beg=0;

    end=n;

    mid=(beg+end)/2;

    printf("\n enter the elements of array");

    for(i=0;i

  • 8/7/2019 ds file original

    13/16

    else

    {

    beg=mid+1;

    }mid=(beg+end)/2;

    }

    if(a[mid]==item)

    {

    printf("\n item is found at location = %d",mid+1);

    }

    else{

    printf("\n item not found so location = NULL");

    }

    getch();

    }

    OUTPUT :

    enter the no. of elements of array 4

    enter the elements of array 1

    2

    3

    45

    enter the item 4

    item is found at location = 4

  • 8/7/2019 ds file original

    14/16

  • 8/7/2019 ds file original

    15/16

  • 8/7/2019 ds file original

    16/16