Data Structures for Exam

download Data Structures for Exam

of 9

Transcript of Data Structures for Exam

  • 7/31/2019 Data Structures for Exam

    1/9

    Ex no: 1120-02-2012 MULTIPLICATION OF 2D ARRAY

    CODING:#includemain(){int a[3][3],b[3][3],c[3][3],i,j,k;printf("Enter the first matrix elements:");for(i=0;i

  • 7/31/2019 Data Structures for Exam

    2/9

    RESULT:A program was created and implemented for multiplying two matrices.

    Ex no: 1220-02-2012 FIBONACCI SERIES

    CODING:#includeint fib(int a, int b, int c, int n);main(){int a=-1,b=1,c=0,n;printf(Enter a number : );scanf("%d",&n);printf("Fibonacci series is");fib(a,b,c,n);}

    int fib(int a, int b, int c, int n)

    {if ( n == 0 )return 0;

    else{c=a+b;a=b;b=c;printf(%d\n,c);fib(a,b,c,n);}}

    OUTPUT:Enter a number : 10Fibonacci series is01123

    58132134

  • 7/31/2019 Data Structures for Exam

    3/9

    RESULT:A program was created and implemented for printing Fibonacci series numb

    ers using the concept of recursive.Ex no: 1323-02-2012 IMPLEMENTATION OF 3D ARRAY

    CODING:#include int a[5][5][5],i,j,k;int num,qty,pri;void input();

    void display();void calc();main(){int ch;input();do{

    printf("\n\t1.Details\n\t2.Purchase\n\t3.Exit\nEnter your Choice: ");scanf ("%d",&ch);switch (ch){case 1:

    display();break;case 2:

    calc();break;

    }}while(ch!=3);

    }void input(){for(i=0;i

  • 7/31/2019 Data Structures for Exam

    4/9

    {printf ("\n\t\t\tITEM DETAILS\n\n");printf ("\n\tItem no\t\tQuantity\t\tRate\n");for(i=0;i

  • 7/31/2019 Data Structures for Exam

    5/9

    3.ExitEnter your choice:2

    ITEM PURCHASINGEnter the item number: 3Item is available...Enter the quantity needed: 3Price of 3 items is: Rs.294/-

    1.Details2.Purchase3.ExitEnter your choice:1

    ITEM DETAILSItem no Qty Rate

    1 6 542 9 783 1 984 12 655 7 66

    1.Details2.Purchase

    3.ExitEnter your choice:3

    RESULT:A program was created and implemented for print purchase details using 3

    D array.Ex no: 1401-03-2012 INFIX TO POSTFIX CONVERSION

    CODING:

    #includemain(){

    char exp[25];int br[10],br2[10];int op[10];int i,j,k,l1,l2,t1,t2,n;printf("\nEnter the expression string\n");scanf("%s",exp);for (i=0,j=0,k=0,n=0; exp[i]!='\0'; i++){if (exp[i] == '('){

    br[j] = i;j++;

    }else if (exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/'){op[k] = i;k++;

    }else if(exp[i]==')'){

  • 7/31/2019 Data Structures for Exam

    6/9

    br2[n]=i;l1 = br2[n];l2 = op[k-1];exp[l1] = exp[l2];l1--;for (;l1>=l2;l2++)

    exp[l2] = exp[l2+1];exp[l2-1] = ')';n++;k++;

    }printf("\nAfter %d iteration : %s",i+1,exp);

    }printf("\nPostfix string is %s",exp);}

    OUTPUT:Enter the expression string: ((2*6)+(8*5))

    After 1 iteration: ((2*6)+(8*5))After 2 iteration: ((2*6)+(8*5))After 3 iteration: ((2*6)+(8*5))After 4 iteration: ((2*6)+(8*5))After 5 iteration: ((2*6)+(8*5))

    After 6 iteration: ((26)*+(8*5))After 7 iteration: ((26)*+(8*5))After 8 iteration: ((26)*+(8*5))After 9 iteration: ((26)*+(8*5))After 10 iteration: ((26)*+(8*5))After 11 iteration: ((26)*+(8*5))After 12 iteration: ((26)*+(85)*)After 13 iteration: ((26)*(85)*+)

    Postfix string is: ((26)*(85)*+)

    RESULT:A program was implemented for convert infix express to a postfix express

    ion.Ex no: 1501-03-2012 EVALUATION OF POSTFIX EXPRESSION

    CODING:#includemain(){

    char exp[25];

    int br[10],br2[10];int op[10];int i,j,k,l1,l2,t1,t2,n;printf("\nEnter the expression string\n");scanf("%s",exp);for (i=0,j=0,k=0,n=0; exp[i]!='\0'; i++){if (exp[i] == '('){br[j] = i;

  • 7/31/2019 Data Structures for Exam

    7/9

    j++;}else if (exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/'){op[k] = i;k++;

    }else if(exp[i]==')'){br2[n]=i;l1 = br2[n];l2 = op[k-1];exp[l1] = exp[l2];l1--;for (;l1>=l2;l2++)

    exp[l2] = exp[l2+1];exp[l2-1] = ')';n++;k++;

    }printf("\nAfter %d iteration : %s",i+1,exp);

    }printf("\nPostfix string is %s",exp);}

    OUTPUT:Enter the expression string: ((2*6)+(8*5))

    After 1 iteration: ((2*6)+(8*5))After 2 iteration: ((2*6)+(8*5))After 3 iteration: ((2*6)+(8*5))After 4 iteration: ((2*6)+(8*5))After 5 iteration: ((2*6)+(8*5))After 6 iteration: ((26)*+(8*5))After 7 iteration: ((26)*+(8*5))After 8 iteration: ((26)*+(8*5))After 9 iteration: ((26)*+(8*5))

    After 10 iteration: ((26)*+(8*5))After 11 iteration: ((26)*+(8*5))After 12 iteration: ((26)*+(85)*)After 13 iteration: ((26)*(85)*+)

    Postfix string is: ((26)*(85)*+)

    Ex no: 1605-03-2012 Towers of Hanoi

    CODING:#includemain(){void tower(int n,char source,char dest,char auxilary);int numdisk;printf("\n Enter the number of disks: ");

  • 7/31/2019 Data Structures for Exam

    8/9

    scanf("%d",&numdisk);printf("\t\t\tSTART TOWER OF HANOI");tower(numdisk,'a','b','c');

    }void tower(int n,char source,char dest,char auxilary){if(n==1){

    printf("\n\tMOVE FROM %c TO %c\n",source,dest);}else{

    tower(n-1,source,auxilary,dest);printf("\n\tMOVE FROM %c TO %c\n",source,dest);tower(n-1,auxilary,dest,source);

    }}

    OUTPUT:

    Enter the number of disks:2

    START OF TOWER OF HANOI

    MOVE FROM a TO cMOVE FROM a TO bMOVE FROM c TO b

    RESULT:

    Ex no: 1705-03-2012 ACKERMANN

    CODING:#includeint m,n,h;main(){printf("Enter the value of M and N: ");scanf("%d%d",&m,&n);acker(m,n);display(m,n);

    }acker(int m,int n){

    if(m==0&&n!=0)

    {h=n+1;

    }else if(m!=0&&n==0){acker(m-1,1);

    }else if(m!=0&&n!=0){acker(m-1,acker(m,n-1));

  • 7/31/2019 Data Structures for Exam

    9/9

    }}display(int m,int n){printf("A(%d,%d)=%d\n",m,n,h);

    }

    OUTPUT:Enter the value of M and N:1 1A(1,1)=3

    RESULT: