Wednesday, 19 October 2011

"C program for polynomial using Linked list"

/*Title :-Represent a Polynomal using a circular linked list and write menu driven program to
  perform addition,multiplication and evaluation.

  */


#include <stdio.h>
#include <conio.h>
#include <math.h>

typedef struct  node
 { int power;
   float coeff;
   struct node *next;
 }node;

      node *  insert(node *head,int power1,float coeff1);
      node *  create();
      node *  padd(node *p1,node *p2);
      node *  pmul(node *p1,node *p2);
      float eval(node *p1,float x);
      void print(node *head);


node *insert(node *head,int power1,float coeff1)
      {  node *p,*q;
     /*terms are store in increasing order of power*/
     /*pointer is used to locate the correct place of insertion.
       pointer p is used to store the address of the node created for
       the current term.If a term with same power is found,coefficients
       are added*/
       p=(node*) malloc(sizeof(node));
       p->power=power1;
       p->coeff=coeff1;
       p->next=NULL;
       if(head==NULL)
     {
          head=p;
          head->next=head;
          return(head);
     }
       if(power1>head->power)
      {
          p->next=head->next;
          head->next=p;
          head=p;
          return(head);
      }
       if(power1==head->power)
      {
          head->coeff=head->coeff+coeff1;
          return(head);
      }

     q=head;
     while(q->next!=head && power1>=q->next->power)
           q=q->next;
     if(p->power==q->power)
           q->coeff=q->coeff+coeff1;
     else
       {
           p->next=q->next;
           q->next=p;
       }
    return(head);
  }


 node *create()
   {
       int n,i,power1;
       float coeff1;
       node *head=NULL;
       printf("\nEnter No. of Terms:");
       scanf("%d",&n);
       printf("\nenter a term as a tuple of (power,coefficient) : ");
       for(i=1;i<=n;i++)
     {   scanf("%d%f",&power1,&coeff1);
         head=insert(head,power1,coeff1);
     }
       return(head);
  }

 node * padd(node *p1,node *p2)
 {   node *p;
     node *head=NULL;
     int power;float coeff;
     p=p1->next;
     do
     {
         head=insert(head,p->power,p->coeff);
         p=p->next;
     } while(p!=p1->next);
     p=p2->next;
     do
     {
         head=insert(head,p->power,p->coeff);
         p=p->next;
     } while(p!=p2->next);
     return(head);
  }

 node *pmul(node *p1,node *p2)
 {   node *head1,*head2;
     node *head=NULL;
     head2=p2->next;
      do
       {  head1=p1->next;
      do
        {
 //    for(p=head1;p!=NULL;p=p->next)
         head=insert(head,head1->power+head2->power,head1->coeff * head2->coeff);
         head1=head1->next;
       }while(head1!=p1->next);
    head2=head2->next;
       }while(head2!=p2->next);
     return(head);
 }

 float eval(node *head,float x)
 {  float value=0.00;
    node *p;
    p=head->next;
    do
       {  value=value+p->coeff * pow(x,p->power);
      p=p->next;
       }while(p!=head->next);
    return(value);
 }

 void print( node *head)
 {  node *p;
    p=head->next;
    printf("\n");
    do
     {
    printf("%6.2fx^%d   ",p->coeff,p->power);
    p=p->next;
     }while(p!=head->next);
 }


 void main()
 { node *p1,*p2,*p3;
   int op;
   float value,x;
   p1=p2=p3=NULL;
   clrscr();
   do
     { printf("\n1)Create first polynomial");
       printf("\n2)Create second polynomial");
       printf("\n3)Print first polynomial");
       printf("\n4)Print second polynomial");
       printf("\n5)Add\n6)Multiply\n7)Evaluate First Polynomial\n8)Quit");
       printf("\nEnter Your Choice: ");
       scanf("%d",&op);
       switch(op)
    { case 1: p1=create();break;
      case 2: p2=create();break;
      case 3: print(p1);break;
      case 4: print(p2);break;
      case 5: p3=padd(p1,p2);
          print(p3);break;
      case 6: p3=pmul(p1,p2);
          print(p3);break;
      case 7: printf("\nEnter the value of X:");
          scanf("%f",&x);
          value=eval(p1,x);
          printf("\nEvaluated value = %6.2f",value);
          break;
      }
       }while(op!=8);
 }

 /*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OUTPUT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


1)Create first polynomial
2)Create second polynomial
3)Print first polynomial
4)Print second polynomial
5)Add
6)Multiply
7)Evaluate First Polynomial
8)Quit

Enter Your Choice: 1

Enter No. of Terms:2

enter a term as a tuple of (power,coefficient) : 1 3 2 1

Enter Your Choice: 3

  3.00x^1     1.00x^2


Enter Your Choice: 2

Enter No. of Terms:2

enter a term as a tuple of (power,coefficient) : 5 1 6 2


Enter Your Choice: 5

  3.00x^1     1.00x^2     1.00x^5     2.00x^6
1)Create first polynomial


Enter Your Choice: 6

  3.00x^6     7.00x^7     2.00x^8

Enter Your Choice: 7

Enter the value of X:2

Evaluated value =  10.00
 */

"C program for merging of two Singly linked list"

/*Merging of linked lists with sorted data
   */

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

typedef struct node
 { int data;
   struct node *next;
 }node;
node *merge(node *l1,node *l2);
node *create_normal();
node *create_sorted();
void print(node *head);
void sort(node *head);
void main()
 { node *head1,*head2,*head3;
   clrscr();
   printf("\nCreating Normal(unsortrd) linked list \n");
   head1=create_normal();
   printf("\nCreating sorted linked list \n");
   head2=create_sorted();
   printf("\nFirst LInked list(Before Sorting):");
   print(head1);
   sort(head1);
   printf("\nFirst Linked list(After Sorting):");
   print(head1);
   printf("\nSecond Linked list:");
   print(head2);
   head3=merge(head1,head2);
   printf("\nFinal List:");
   print(head3);
   getch();
 }
node *merge(node *l1,node *l2)
   { node *l,*p;
     l=NULL;
     while(l1!=NULL && l2!=NULL)
       { if(l1->data < l2->data)
       { if(l==NULL)
          { l=p=l1;
        l1=l1->next;
          }
         else
          { p->next=l1;
        l1=l1->next;
        p=p->next;
          }
       }
     else
       { if(l==NULL)
          { l=p=l2;
        l2=l2->next;
          }
         else
          { p->next=l2;
        l2=l2->next;
        p=p->next;
          }
       }
      }
      if(l1!=NULL)
       { if(l==NULL)
       l=l1;
     else
       p->next=l1;
       }
      if(l2!=NULL)
       { if(l==NULL)
       l=l2;
     else
       p->next=l2;
       }
    return(l);
  }
 node *create_normal()
  { node *head=NULL,*p;
    int n,x,i;
    printf("\nNumber of nodes:");
    scanf("%d",&n);
    printf("\nEnter data:");
    for(i=1;i<=n;i++)
     { scanf("%d",&x);
       if(head==NULL)
     { p=head=(node*)malloc(sizeof(node));
       p->next=NULL;
     }
       else
    {p->next=(node*)malloc(sizeof(node));
    p=p->next;
    p->next=NULL;
    }
       p->data=x;
    }
   return(head);
 }
node *create_sorted()
  { node *head=NULL,*p,*q;
    int n,x,i;
    printf("\nNumber of nodes:");
    scanf("%d",&n);
    printf("\nEnter data:");
    for(i=1;i<=n;i++)
     { scanf("%d",&x);
       p=(node*)malloc(sizeof(node));
       p->data=x;
       p->next=NULL;
       if(head==NULL || x<head->data)
      { p->next=head;
        head=p;
      }
       else
    { q=head;
      while(q->next !=NULL && x>q->next->data)
        q=q->next;
      p->next=q->next;
      q->next=p;
    }
     }
   return(head);
 }
 void print(node *head)
  { printf("\n");
   while(head != NULL)
    { printf("%5d",head->data);
      head=head->next;
    }
  }
void sort(node *head)
  { int i,j,n,temp;
    node *p;
   /*counting number of nodes*/
    for(n=0,p=head;p!=NULL;p=p->next)
       n++;
    for(i=1;i<n;i++)
     {p=head;
      for(j=0;j<n-i;j++)
       {if(p->data > p->next->data)
      { temp=p->data;
        p->data=p->next->data;
        p->next->data=temp;
      }
    p=p->next;
       }
      }
    }
    /*
    OUTPUT:-

Creating Normal(unsortrd) linked list

Number of nodes:2

Enter data:42 12

Creating sorted linked list

Number of nodes:3

Enter data:12 68 41

First LInked list(Before Sorting):
   42   12
First Linked list(After Sorting):
   12   42
Second Linked list:
   12   41   68
Final List:
   12   12   41   42   68

    */



                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               

"C program on singly linked list"

/*Operations on SLL(singly linked list)*/


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
   { int data;
     struct node *next;
   }node;

node *create();
node *insert_b(node *head,int x);
node *insert_e(node *head,int x);
node *insert_in(node *head,int x);
node *delete_b(node *head);
node *delete_e(node *head);
node *delete_in(node *head);
node *reverse(node *head);
void search(node *head);
void print(node *head);

void main()
{ int op,op1,x;
  node *head=NULL;
  clrscr();
  do
    {
      printf("\n\n1)create\n2)Insert\n3)Delete\n4)Search");
      printf("\n5)Reverse\n6)Print\n7)Quit");
      printf("\nEnter your Choice:");
      scanf("%d",&op);
      switch(op)
       { case 1:head=create();break;
     case 2:printf("\n\t1)Beginning\n\t2)End\n\t3)In between");
        printf("\nEnter your choice : ");
        scanf("%d",&op1);
        printf("\nEnter the data to be inserted : ");
        scanf("%d",&x);
        switch(op1)
         {  case 1: head=insert_b(head,x);
                break;
            case 2: head=insert_e(head,x);
                break;
            case 3: head=insert_in(head, x);
                break;
          }
        break;
     case 3:printf("\n\t1)Beginning\n\t2)End\n\t3)In between");
        printf("\nEnter your choice : ");
        scanf("%d",&op1);
        switch(op1)
         {  case 1:head=delete_b(head);
               break;
            case 2:head=delete_e(head);
               break;
            case 3:head=delete_in(head);
               break;
          }
         break;
     case 4:search(head);break;
     case 5:head=reverse(head);
        print(head);
        break;
     case 6:print(head);break;
       }
    }while(op!=7);
}

node *create()
{ node *head,*p;
  int i,n;
  head=NULL;
  printf("\n Enter no of data:");
  scanf("%d",&n);
  printf("\nEnter the data:");
  for(i=0;i<n;i++)
   {
     if(head==NULL)
     p=head=(node*)malloc(sizeof(node));
     else
       {
     p->next=(node*)malloc(sizeof(node));
     p=p->next;
       }
       p->next=NULL;
       scanf("%d",&(p->data));
   }
 return(head);
}

node *insert_b(node *head,int x)
{   node *p;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=head;
    head=p;
    return(head);
}

node *insert_e(node *head,int x)
{   node *p,*q;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=NULL;
    if(head==NULL)
       return(p);
    //locate the last node
    for(q=head;q->next!=NULL;q=q->next);
    q->next=p;
    return(head);
}

node *insert_in(node *head,int x)
{   node *p,*q;
    int y;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=NULL;
    printf("\Insert after which number ? : ");
    scanf("%d",&y);
    //locate the lthe data 'y'
    for(q=head ; q != NULL && q->data != y ; q=q->next)
    ;
    if(q!=NULL)
      {
    p->next=q->next;
    q->next=p;
      }
    else
       printf("\nData not found ");
    return(head);
}
node *delete_b(node *head)
{
  node *p,*q;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  p=head;
  head=head->next;
  free(p);
  return(head);

}
node *delete_e(node *head)
{
  node *p,*q;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  p=head;
  if(head->next==NULL)
     { // Delete the only element
       head=NULL;
       free(p);
       return(head);
     }
//Locate the last but one node
   for(q=head;q->next->next !=NULL;q=q->next)
   ;
   p=q->next;
   q->next=NULL;
   free(p);
   return(head);
}
node *delete_in(node *head)
{
  node *p,*q;
  int x,i;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  printf("\nEnter the data to be deleted : ");
  scanf("%d",&x);
  if(head->data==x)
     { // Delete the first element
       p=head;
       head=head->next;
       free(p);
       return(head);
     }
//Locate the node previous to one to be deleted
   for(q=head;q->next->data!=x && q->next !=NULL;q=q->next )
   ;
   if(q->next==NULL)
     {
       printf("\nUnderflow.....data not found");
       return(head);
     }
   p=q->next;
   q->next=q->next->next;
   free(p);
   return(head);
}

void search(node *head)
{ node *p;
  int data,loc=1;
  printf("\nEnter the data to be searched: ");
  scanf("%d",&data);
  p=head;
  while(p!=NULL && p->data != data)
   { loc++;
     p=p->next;
   }

  if(p==NULL)
   printf("\nNot found:");
  else
   printf("\nFound at location=%d",loc);
}
void print(node *head)
{ node *p;
 printf("\n\n");
 for(p=head;p!=NULL;p=p->next)
  printf("%d  ",p->data);
}

node *reverse(node *head)
  { node *p,*q,*r;
    p=NULL;
    q=head;
    r=q->next;
    while(q!=NULL)
      {
    q->next=p;
    p=q;
    q=r;
    if(q!=NULL)
       r=q->next;
      }
   return(p);
  }
  /*
  OUTPUT:-
1)create
2)Insert
3)Delete
4)Search
5)Reverse
6)Print
7)Quit
Enter your Choice:1

Enter no of data:2

Enter the data:23 34

Enter your Choice:2

    1)Beginning
    2)End
    3)In between
Enter your choice : 2

Enter the data to be inserted : 25

Enter your Choice:3

    1)Beginning
    2)End
    3)In between
Enter your choice : 3

Enter the data to be deleted : 34

1)create
2)Insert
3)Delete
4)Search
5)Reverse
6)Print
7)Quit
Enter your Choice:7

Enter your Choice:4

Enter the data to be searched: 34

Not found:

Enter your Choice:5

25  23

Enter your Choice:6

25  23
*/

"C program for Sparse matrix"

/*
  Represent sparse matrix using array and perform matrix addition,simple
  transpose and fast transpose */
#include<stdio.h>
#include<conio.h>
#define MAX 20
void printsparse(int[][3]);
void readsparse(int[][3]);
void transpose(int[][3],int[][3]);
void Fast_transpose(int B1[MAX][3],int B2[MAX][3]);
void addsparse(int b1[MAX][3],int b2[MAX][3],int b3[MAX][3]);
void main()
{
    int b1[MAX][3],b2[MAX][3],m,n,b3[MAX][3],op;
    clrscr();
    do
      {
        printf("\n1)Read the First Sparse Matrix");
        printf("\n2)Read the second sparse matrix");
        printf("\n3)Display the first matrix");
        printf("\n4)Display the second matrix");
        printf("\n5)Addition of two matrices");
        printf("\n6)Simple transpose of the first matrix");
        printf("\n7)Fast transpose of the first matrix");
        printf("\n8)Quit");
        printf("\nEnter your choice : ");
        scanf("%d",&op);
        switch(op)
         {
        case 1: readsparse(b1);break;
        case 2: readsparse(b2);break;
        case 3: printsparse(b1);break;
        case 4: printsparse(b2);break;
        case 5: addsparse(b1,b2,b3);printsparse(b3);break;
        case 6: transpose(b1,b3);printsparse(b3);break;
        case 7: Fast_transpose(b1,b3);printsparse(b3);break;
         }
     }while(op!=8);
}
void readsparse(int b[MAX][3])
{
    int i,t,m,n;

    printf("\n Enter the size of matrix (rows,columns)");
    scanf("%d%d",&m,&n);
    b[0][0]=m;
    b[0][1]=n;

    printf("\nEnter no. of non-zero elements:");
    scanf("%d",&t);
    b[0][2]=t;
    for(i=1;i<=t;i++)
    {
        printf("\n Enter the next triple(row,column,value) :");
        scanf("%d%d%d",&b[i][0],&b[i][1],&b[i][2]);
    }
}
void printsparse(int b[MAX][3])
{
    int i,n;
    n=b[0][2];   //no of 3-triples
    printf("\nrows = %d\tcolumns = %d",b[0][0],b[0][1]);
    printf("\n");
    for(i=1;i<=n;i++)
        printf("%d\t%d\t%d\n",b[i][0],b[i][1],b[i][2]);
}
void transpose(int b1[][3],int b2[][3])
{
    int i,j,k,n;
    b2[0][0]=b1[0][1];
    b2[0][1]=b1[0][0];
    b2[0][2]=b1[0][2];
    k=1;
    n=b1[0][2];
    for(i=0;i<b1[0][1];i++)
        for(j=1;j<=n;j++)
    /* if a column number of current triple == i
       then insert the current triple in b2 */
        if(i== b1[j][1])
        {
            b2[k][0]=i;
            b2[k][1]=b1[j][0];
            b2[k][2]=b1[j][2];
            k++;
        }
}

void Fast_transpose(int B1[MAX][3],int B2[MAX][3])
{
    int m,n,t,i,col_num,location;
    int total[MAX],index[MAX];
    m=B1[0][0];n=B1[0][1];t=B1[0][2];
    B2[0][0]=n;B2[0][1]=m;B2[0][2]=t;
    for(i=0;i<n;i++)
        total[i]=0;
    for(i=1;i<=t;i++)
    {
        col_num=B1[i][1];
        total[col_num]++;
    }
    index[0]=1;
    for(i=1;i<n;i++)
        index[i]=index[i-1]+total[i-1];

    for(i=1;i<=t;i++)
    {
        col_num=B1[i][1];
        location=index[col_num];
        index[col_num]++;
        B2[location][0]=B1[i][1];
        B2[location][1]=B1[i][0];
        B2[location][2]=B1[i][2];
    }
}

void addsparse(int b1[MAX][3],int b2[MAX][3],int b3[MAX][3])
{
    int t1,t2,i,j,k;
    t1=b1[0][2];
    t2=b2[0][2];
    i=j=k=0;
    b3[0][0]=b1[0][0];
    b3[0][1]=b1[0][1];
    while(i<=t1 && j<=t2)
    {
        if(b1[i][0] < b2[j][0])
        {
            b3[k][0]=b1[i][0];
            b3[k][1]=b1[i][1];
            b3[k][2]=b1[i][2];
            k++;
            i++;
            continue;//go to  end of the loop
        }
        if(b2[j][0] < b1[i][0])
        {
            b3[k][0]=b2[j][0];
            b3[k][1]=b2[j][1];
            b3[k][2]=b2[j][2];
            k++;
            j++;
            continue;//go to end of loop
        }
        if(b1[i][1] < b2[j][1])
        {
            b3[k][0]=b1[i][0];
            b3[k][1]=b1[i][1];
            b3[k][2]=b1[i][2];
            k++;
            i++;
            continue;//go to end of loop
        }
        if(b2[j][1] < b1[i][1])
        {
            b3[k][0]=b2[j][0];
            b3[k][1]=b2[j][1];
            b3[k][2]=b2[j][2];
            k++;
            j++;
            continue; //go to end of loop
        }
//else add the two tuples
        b3[k][0]=b1[i][0];
        b3[k][1]=b1[i][1];
        b3[k][2]=b1[i][2]+b2[j][2];
        k++;
        i++;
        j++;

     }
        while(i<=t1)
        {
            b3[k][0]=b1[i][0];
            b3[k][1]=b1[i][1];
            b3[k][2]=b1[i][2];
            i++;
            k++;
        }
        while(j<=t2)
        {
            b3[k][0]=b2[j][0];
            b3[k][1]=b1[j][1];
            b3[k][2]=b1[j][2];
            j++;
            k++;
        }
        b3[0][2]=k-1;
  }
  /*
  OUTPUT:-

1)Read the First Sparse Matrix
2)Read the second sparse matrix
3)Display the first matrix
4)Display the second matrix
5)Addition of two matrices
6)Simple transpose of the first matrix
7)Fast transpose of the first matrix
8)Quit
Enter your choice : 1

Enter the size of matrix (rows,columns)2 2

Enter no. of non-zero elements:3

Enter the next triple(row,column,value) :2 3 5

Enter the next triple(row,column,value) :0 2 1

Enter the next triple(row,column,value) :2 5 8

Enter your choice : 2

Enter the size of matrix (rows,columns)2 2

Enter no. of non-zero elements:3

Enter the next triple(row,column,value) :4 5 7

Enter the next triple(row,column,value) :3 5 9

Enter the next triple(row,column,value) :3 0 3

Enter your choice : 3

rows=2    columns=2

2      3       5
0      2       1
2      5       8

Enter your choice : 4

rows=2          columns=2
4      5       7
3      5       9
3      0       3

Enter your choice : 5

rows = 2        columns = 2
2       3       5
0       2       1
2       5       8
4       3       5
3       2       1
3       5       8

Enter your choice : 6

rows = 2        columns = 2
2       3       5
0       2       1
2       5       8


Enter your choice : 7

rows = 2        columns = 2
2       0       1
3       2       5
2       5       8
*/


"C program for polynomial usng structure"

/*Various operations on polynomials using structures.
 */

#include<math.h>
#include<stdio.h>
//#include<conio.h>
typedef struct term
{
    int power;
    float coeff;
}term;
typedef struct polynomial
{
    term a[20];
    int n;
}polynomial;
void init(polynomial *ptr);
void read(polynomial *ptr);
void print(polynomial *ptr);
polynomial add(polynomial *p1,polynomial *p2);
polynomial multiply(polynomial *p1,polynomial *p2);
float evaluate(polynomial *p1,float x);
void insert(polynomial *,term);
int main()
{
    polynomial P1,P2,P3;
    int option;
    float x,value;
    clrscr();
    do
    {
        printf("\n1 : create 1'st polynomial");
        printf("\n2 : create 2'nd polynomial");
        printf("\n3 : Add polynomials");
        printf("\n4 : Multiply polynomials");
        printf("\n5 : Evaluate 1'st polynomial");
        printf("\n6 : Quit");
        printf("\nEnter your choice :");
        scanf("%d",&option);
        switch(option)
        {
            case 1:read(&P1);break;
            case 2:read(&P2);break;
            case 3:P3=add(&P1,&P2);
                   printf("\n1'st polynomial -> ");
                   print(&P1);
                   printf("\n2'nd polynomial -> ");
                   print(&P2);
                   printf("\n Sum = ");
                   print(&P3);
                   break;
            case 4:P3=multiply(&P1,&P2);
                   printf("\n1'st polynomial -> ");
                   print(&P1);
                   printf("\n2'nd polynomial -> ");
                   print(&P2);
                   printf("\n Product = ");
                   print(&P3);
                   break;
            case 5:printf("\nEnter the value of x:");
                   scanf("%f",&x);
                   value=evaluate(&P1,x);
                   printf("\nValue of Polynomial =%6.2f",value);
                   break;
        }
    }while(option!=6);
return 0;
}
void read(polynomial *Ptr)
{
    int n, i, power;
    float coeff;
    term t;
    init(Ptr);
    printf("\n Enter number of terms :");
    scanf("%d",&n);
    /* read n terms */
    for (i=0;i<n;i++)
    {       printf("\nenter a term(power  coeff.)");
        scanf("%d%f",&power,&coeff);
        t.power=power;
        t.coeff=coeff;
        insert(Ptr,t);
    }
}
void print(polynomial *Ptr)
{
    int i;
    printf("%5.2fX^%d ",(Ptr->a[0]).coeff,(Ptr->a[0]).power);
    for(i=1;i<Ptr->n;i++)
      printf(" + %5.2fX^%d ",(Ptr->a[i]).coeff,(Ptr->a[i]).power);
}
polynomial add(polynomial *P1, polynomial *P2)
{
    polynomial P3;
    term t;
    int i,j;
    i=j=0;
    init(&P3);
    while(i<P1->n && j<P2->n)
    {
        if(P1->a[i].power==P2->a[j].power)
        {
            t.power=P1->a[i].power;
            t.coeff=P1->a[i].coeff+P2->a[j].coeff;
            insert(&P3,t);
            i++;j++;
        }
        else
            if(P1->a[i].power < P2->a[j].power)
            {
                insert(&P3,P1->a[i]);
                i++;
            }
            else
            {
                insert(&P3,P2->a[j]);
                j++;
            }
    }
    while(i<P1->n)
    {
         insert(&P3,P1->a[i]);
         i++;
    }
    while(j<P2->n)
    {
         insert(&P3,P2->a[j]);
         j++;
    }
    return(P3);
}
polynomial multiply(polynomial *P1,polynomial *P2)
{
    polynomial P3, Ptemp;
    term t;
    int i,j;
    init(&P3);
    for(i=0;i<P2->n;i++)
    {
        init(&Ptemp);
        for(j=0;j<P1->n;j++)
        {
            t.power=P1->a[j].power+P2->a[i].power;
            t.coeff=P1->a[j].coeff*P2->a[i].coeff;                                        insert (&Ptemp, t);
        }
    P3=add(&P3,&Ptemp);
    }
    return(P3);
}
float evaluate(polynomial *P, float x)
{
    float value;
    int i,power;
    value=0.00;
    for(i=0;i<P->n;i++)
     { power=P->a[i].power;
    value=value+(P->a[i].coeff)*pow(x,power);
      }
    return(value);
}
void init(polynomial *Ptr)
{
    Ptr->n=0;
}
void insert(polynomial *Ptr,term t)
{
    int i;
    /* move all higher power term by 1 place.movement
       should start with the last term */
    for(i=Ptr->n-1; (Ptr->a[i]).power > t.power && i>=0;i--)
        Ptr->a[i+1]=Ptr->a[i];
    /* insert the term t */
    Ptr->a[i+1]=t;
    (Ptr->n)++;
}
/*
OUTPUT:-

1 : create 1'st polynomial
2 : create 2'nd polynomial
3 : Add polynomials
4 : Multiply polynomials
5 : Evaluate 1'st polynomial
6 : Quit
Enter your choice :1

Enter number of terms :2

enter a term(power  coeff.)2 3

enter a term(power  coeff.)3 4


Enter your choice :2

Enter number of terms :2

enter a term(power  coeff.)2 4

enter a term(power  coeff.)3 3

Enter your choice :3

1'st polynomial ->  3.00X^2  +  2.00X^3

2'nd polynomial ->  4.00X^2  +  3.00X^3
Sum =  7.00X^2  +  5.00X^3

Enter your choice :4
1'st polynomial ->  3.00X^2  +  2.00X^3
2'nd polynomial ->  4.00X^2  +  3.00X^3
Product = 12.00X^4  + 17.00X^5  +  6.00X^6

Enter your choice :5
Enter the value of x:12
Value of Polynomial =3888.00
*/
/* DIFFERENT SEARCHING TECHNIQUES
1)FIBONACCI SEARCH 2)BINARY SEARCH 3)LINEAR SEARCH 4)INDEX SEQUENTIAL
SEARCH
NAME:-SKAND KUMAR(S.E comp-46 ) */
#include<stdio.h>
#include<conio.h>
int fib(int n);
int fibsearch(int a[],int key,int mid,int p,int q);
int binsearch(int a[],int i,int j,int key);
int seqsearch(int a[],int n,int key);
int index_sequential(int a[],int n,int key);
void main()
{
int a[30],key,mid,p,q,k,n,i,result,op;
clrscr();
do
{
printf("\n1]sequential search 2]binary search 3]fibonaci search");
printf("\n4]index sequential search 5]quit");
printf("\nEnter your choice:");
scanf("%d",&op);
switch(op)
{
case 1:printf("\n Enter no of elements:");
scanf("%d",&n);
printf("\n Enter a list of %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter the element to be searched:");
scanf("%d",&key);
result=seqsearch(a,n,key);
if(result==-1)
printf("\n not found:");
else
printf("\n found at location=%d",result);
break;

case 2:printf("\n Enter no of elements:");
scanf("%d",&n);
printf("\n Enter a sorted list of %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter the element to be searched:");
scanf("%d",&key);
result=binsearch(a,0,n-1,key);
if(result==-1)
printf("\n not found:");
else
printf("\n found at location=%d",result);
break;

case 3:printf("\n Enter no of elements:");
scanf("%d",&n);
printf("\n Enter a sorted list of %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter the element to be searched:");
scanf("%d",&key);
for(k=1;fib(k)<=n;k++);
p=fib(k-2);
q=fib(k-3);
mid=n-p+1;
result=fibsearch(a,key,mid,p,q);
if(result==-1)
printf("\n not found:");
else
printf("\n found at location=%d",result);
break;

case 4:printf("\n Enter no of elements:");
scanf("%d",&n);
printf("\n Enter a list of %d elements:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter the element to be searched:");
scanf("%d",&key);
result=index_sequential(a,n,key);
if(result==-1)
printf("\n not found:");
else
printf("\n found at location=%d",result);
break;
}
}
while(op!=5);
}
int fib(int n)
{
if(n==0) return(0);
if(n==1) return(1);
return(fib(n-1)+fib(n-2));
}
int fibsearch(int a[],int key,int mid,int p,int q)
{
int temp;
if(key==a[mid])
return(mid);
if(key>a[mid])
{
if(p==1)
return(-1);
mid=mid+q;
p=p-q;
q=q-p;
return(fibsearch(a,key,mid,p,q));
}
else
{
if(q==0)
return(-1);
mid=mid-q;
temp=p-q;
p=q;
q=temp;
return(fibsearch(a,key,mid,p,q));
}
}
int binsearch(int a[],int i,int j,int key)
{
int c;
if(i>j)
return(-1);
c=(i+j)/2;
if(key==a[c])
return(c);
if(key>a[c])
return(binsearch(a,c+1,j,key));
return(binsearch(a,i,c-1,key));
}
int seqsearch(int a[],int n,int key)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==key)
return(i);
}
return(-1);
}
int index_sequential(int a[],int n,int key)
{
 int keys[6],index[6],i,j,temp,n1,start;
for(i=1;i<n;i++)
for(j=0;j<n-i;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
n1=0;
for(i=0;i<n;i=i+4)
{
keys[n1]=a[i];
index[n1]=i;
n1++;
}
if(key<keys[0])
return(-1);
for(i=0;i<n1;i++)
if(key<keys[i])
break;
start=index[i-1];
for(i=start;i<start+4 && i<n;i++)
if(a[i]==key)
return(i);
return(-1);
}

/*
1]sequential search 2]binary search 3]fibonaci search
4]index sequential search 5]quit
Enter your choice:1
 Enter no of elements:5
 Enter a list of 5 elements:90 2 60 35 40
 Enter the element to be searched:40
 found at location=4

1]sequential search 2]binary search 3]fibonaci search
4]index sequential search 5]quit
Enter your choice:2
 Enter no of elements:5
 Enter a sorted list of 5 elements:1 2 3 4 5
 Enter the element to be searched:3
 found at location=2

1]sequential search 2]binary search 3]fibonaci search
4]index sequential search 5]quit
Enter your choice:3
 Enter no of elements:5
 Enter a sorted list of 5 elements:1
2
3
4
5
 Enter the element to be searched:0
 not found:

1]sequential search 2]binary search 3]fibonaci search
4]index sequential search 5]quit
Enter your choice:4
 Enter no of elements:5
 Enter a list of 5 elements:1 2 3 4 5
 Enter the element to be searched:2
 found at location=1

1]sequential search 2]binary search 3]fibonaci search
4]index sequential search 5]quit
Enter your choice:5
*/






"C program for sorting operation usig recursion"

/*Implement Quick sort and Mege sort using recursion*/

#include<conio.h>
#include<stdio.h>
void quick_sort(int [],int,int);
int partition(int [],int,int);
void mergesort(int a[] ,int i , int j);
void merge(int a[],int i1, int j1, int i2, int j2);
void main()
{
    int a[30],n,i,op;
    clrscr();
    do
       {
         printf("\n1)Quick Sort\n2)Merge Sort \n3)Quit");
         printf("\nEnter your choice : ");
         scanf("%d",&op);
         switch(op)
          {
        case 1: printf("\nEnter no of elements :");
            scanf("%d",&n);
            printf("\nEnter array elements :");
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            quick_sort(a,0,n-1);
            printf("\nSorted array is :");
            for(i=0;i<n;i++)
                printf("%d  ",a[i]);
            break;

        case 2: printf("\nEnter no of elements :");
            scanf("%d",&n);
            printf("\nEnter array elements :");
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            mergesort(a,0,n-1);
            printf("\nSorted array is :");
            for(i=0;i<n;i++)
                printf("%d   ",a[i]);
            break;

       }
     }while(op!=3);
}
void quick_sort(int a[],int l,int u){
    int j;
    if(l<u)
    {
        j=partition(a,l,u);
        quick_sort(a,l,j-1);
        quick_sort(a,j+1,u);
    }
}
int partition(int a[],int l,int u)
{
    int v,i,j,temp;
    v=a[l];
    i=l;
    j=u+1;
    do
    {
    do
    {    i++;
    }while(a[i]<v && i<=u);

    do
    {    j--;
    }while(a[j]>v);

    if(i<j)
    {
        temp=a[i];
        a[i]=a[j];
        a[j]=temp;
    }
    }while(i<j);
    a[l]=a[j];
    a[j]=v;
    return(j);
}

 void mergesort(int a[] ,int i , int j)
   {
    int mid;
    if(i<j)
     { mid=(i+j)/2;
       mergesort(a,i,mid);    //left recursion
       mergesort(a,mid+1,j);  //right recursion
       merge(a,i,mid,mid+1,j); //meging of two sorted sub-arrays
     }
    }


void merge(int a[],int i1, int j1, int i2, int j2)
  {
     int temp[50];//array used for merging
     int i,j,k;
     i=i1;//beginning of the first list
     j=i2;//beginning of the second list
     k=0;
     while(i<=j1 && j <=j2) //while elemnts in both lists
      {
    if(a[i]<a[j])
       temp[k++]=a[i++];
    else
       temp[k++]=a[j++];
      }
    while(i<=j1)//copy remaining elements of the first list
       temp[k++]=a[i++];
    while(j<=j2)//copy remaining elements of the second list
       temp[k++]=a[j++];
  //Transfer elemnts from temp[] back to a[]
    for(i=i1,j=0;i<=j2;i++,j++)
       a[i]=temp[j];
  }

/*
OUTPUT:-
1)Quick Sort
2)Merge Sort
3)Quit
Enter your choice : 1

Enter no of elements :5

Enter array elements :6 5 4 3 89

Sorted array is :3  4  5  6  89



Enter your choice : 2

Enter no of elements :4

Enter array elements :89 65 23 48

Sorted array is :23   48   65   89
*/














                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               

"C program for Sorting operation using function"

/* DIFFERENT SORTING TECHNIQUES
  1)BUBBLE SORT 2)SELECTION SORT 3)INSERTION SORT 5)SHELL SORT */
#include<stdio.h>
#include<conio.h>
int a[60],n,i,j,k,temp,choice;
void bubble_sort();
void selection_sort();
void insertion_sort();
void shell_sort();
void main()
{
    clrscr();
    do
    {
        printf("\n 1]BUBBLE. \n2]SELECTION..\n3]INSERTION. \n4]SHELL. 5]QUIT.");
        printf("\n ENTER YOUR CHOICE:");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1: printf("\n ENTER NO OF ELEMENTS:");
            scanf("%d",&n);
            printf("\n ENTER ARRAY ELEMENTS:");
            for(i=0;i<n;i++)
            scanf("%d",&a[i]);
            bubble_sort();
            break;

            case 2: printf("\n ENTER NO OF ELEMENTS:");
                  scanf("%d",&n);
                   printf("\n ENTER ARRAY ELEMENTS:");
                  for(i=0;i<n;i++)
                  scanf("%d",&a[i]);
                  selection_sort();
                  break;

            case 3: printf("\n ENTER NO OF ELEMENTS:");
                  scanf("%d",&n);
                   printf("\n ENTER ARRAY ELEMENTS:");
                  for(i=0;i<n;i++)
                  scanf("%d",&a[i]);
                  insertion_sort();
                  break;

            case 4: printf("\n ENTER NO OF ELEMENTS:");
                  scanf("%d",&n);
                   printf("\n ENTER ARRAY ELEMENTS:");
                  for(i=0;i<n;i++)
                  scanf("%d",&a[i]);
                  shell_sort();
                  break;
            }
}
while (choice!=5);
getch();
}

void bubble_sort()
{
for(i=0;i<n;i++)
printf("\n UNSORTED DATA:");
for(k=0;k<n;k++)
printf("%5d",a[k]);
for(i=1;i<n;i++)
{
for(j=0;j<n-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
printf("\n AFTER PASS   %d",i);
for(k=0;k<n;k++)
printf("%5d",a[k]);
}
}
void selection_sort()
{
printf("\n UNSORTED DATA:");
for(k=0;k<n;k++)
printf("%5d",a[k]);
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(a[j]<a[k])
k=j;
temp=a[i];
a[i]=a[k];
a[k]=temp;
printf("\n AFTER PASS   %d",i+1);
for(k=0;k<n;k++)
printf("%5d",a[k]);
}
}
void insertion_sort()
{
printf("\n UNSORTED DATA:");
for(k=0;k<n;k++)
printf("%5d",a[k]);
for(i=1;i<n;i++)
{
temp=a[i];
for(j=i-1;j>=0 && a[j]>temp;j--)
a[j+1]=a[j];
a[j+1]=temp;
printf("\n AFTER PASS   %d",i);
for(k=0;k<n;k++)
printf("%5d",a[k]);
}
}

void shell_sort()
{
int step,pass=1;
printf("\n UNSORTED DATA:");
for(i=0;i<n;i++)
printf("%5d",a[i]);
for(step=step/2;step>0;step=step/2)
for(i=step;i<n;i++)
{
temp=a[i];
for(j=i;j>=step;j=j-step)
{
if(temp<a[j-step])
a[j]=a[j-step];
else
break;
}
a[j]=temp;
}
printf("\n AFTER PASS   %d",pass);
for(i=0;i<n;i++)
printf("%5d",a[i]);
pass++;
}

/*
OUTPUT:-
 1]BUBBLE.
2]SELECTION..
3]INSERTION.
4]SHELL. 5]QUIT.
 ENTER YOUR CHOICE:1
 ENTER NO OF ELEMENTS:4

 ENTER ARRAY ELEMENTS:89 56 74 21
 UNSORTED DATA:
 UNSORTED DATA:   89   56   74   21
 AFTER PASS   1   56   74   21   89
 AFTER PASS   2   56   21   74   89
 AFTER PASS   3   21   56   74   89

 ENTER YOUR CHOICE:2

 ENTER NO OF ELEMENTS:3

 ENTER ARRAY ELEMENTS:78 569 84

 UNSORTED DATA:   78  569   84
 AFTER PASS   1   78  569   84
 AFTER PASS   2   78   84  569

 ENTER YOUR CHOICE:3

 ENTER NO OF ELEMENTS:4

 ENTER ARRAY ELEMENTS:41 20 3 64

 UNSORTED DATA:   41   20    3   64
 AFTER PASS   1   20   41    3   64
 AFTER PASS   2    3   20   41   64
 AFTER PASS   3    3   20   41   64

 ENTER YOUR CHOICE:4

 ENTER NO OF ELEMENTS:8

 ENTER ARRAY ELEMENTS:45 87 25 69 74 12 54 98

 UNSORTED DATA:   45   87   25   69   74   12   54   98
 AFTER PASS   1   12   25   45   54   69   74   87   98
*/

"C program for Database operation"

#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct student
{
int rollno;
 char name[20];
 int marks;
}student;
void insert(student st[],int position,int n);
void delete(student st[],int position,int n);
int search(student st[],int rollno,int n);
void print(student st[],int n);
void read(student st[],int n);
void sort(student st[],int n);
void modify(student st[],int n);
void main()
{
student st[30];
 int n,i,op,position,rollno;
 clrscr();
 do{
    flushall();
    printf("\n 1]create 2]insert 3]delete 4] search 5]print 6]sort 7]modify\n");
    printf("\n8]quit");
    printf("\nEnter your choice:");
    scanf("%d",&op);
    switch(op)
    {
     case 1:printf("\nEnter no. of student:");
     scanf("%d",&n);
     read(st,n);
     break;
     case 2:printf("\n enter the position(no. of records=%d):",n);
     scanf("%d",&position);
     if(position<=n+1)
     {
      insert(st,position,n);
      n++;
      print(st,n);
     }
     else
     printf("\n can not insert");
     break;
     case 3:printf("\nenter the roll no:");
     scanf("%d",&rollno);
     position=search(st,rollno,n);
     if(position!=-1)
     {
      delete(st,position,n);
      n--;
      print(st,n);
      }
      else
       {
         printf("\n can not delete");
         }
        break;
     case 4:printf("\nenter roll no:");
     scanf("%d",&rollno);
     position=search(st,rollno,n);
     if(position==-1)
{

     printf("\nnot found");
}
     else
     {
      printf("\n found at location=%d",position+1);
      printf("\n%s\t%d\t%d",st[position].name,st[position].rollno,st[position].marks);
     }

     break;
     case 5:print(st,n);
     break;
     case 6:sort(st,n);print(st,n);break;
     case 7:modify(st,n);break;
 }
 }
  while(op!=8);
 }
  void insert(student st[],int position,int n)
  {
   int i;
   printf("\nenter data(name rollno marks):");
   for(i=n-1;i>=position-1;i--)
   st[i+1]=st[i];
   scanf("%s%d%d",st[position-1].name,&st[position-1].rollno,&st[position-1].marks);
  }
  void delete(student st[],int position,int n)
  {
   int i;
   for(i=position+1;i<n;i++)
   st[i-1]=st[i];
  }
   int search(student st[],int rollno,int n)
    {
      int i;
for(i=0;i<n;i++)
if(rollno==st[i].rollno)
return(i);
return(-1);
}
void print(student st[],int n)
{ int i;
for(i=0;i<n;i++)
printf("\n%20s%5d%5d",st[i].name,st[i].rollno,st[i].marks);
}
void read(student st[],int n)
{
int i;
printf("\nEnter data(name rollno marks):");
for(i=0;i<n;i++)
scanf("%s%d%d",st[i].name,&st[i].rollno,&st[i].marks);
}
void modify(student st[],int n)
{
 int rollno,i;
printf("\nenter the rollno:");
scanf("%d",&rollno);
i=search(st,rollno,n);
if(i==-1)
printf("\n No such rollno");
else
{
printf("\nEnter data(name rollno marks):");
scanf("%s%d%d",st[i].name,&st[i].rollno,&st[i].marks);
}
}
void sort(student st[],int n)
{
int i,j;
student temp;
for(i=1;i<n;i++)
for(j=0;j<n-i;j++)
if(st[j].rollno>st[j+1].rollno)
{
temp=st[j];
st[j]=st[j+1];
st[j+1]=temp;
}
}

/*
OUTPUT:-

 1]create 2]insert 3]delete 4] search 5]print 6]sort 7]modify                  
                                                                               
8]quit
Enter your choice:1                                                            
                                                                               
Enter no. of student:2                                                         
                                                                               
Enter data(name rollno marks):jang 34 50                                       
akshay 44 55                                                                   


Enter your choice:2

 enter the position(no. of records=2):2

enter data(name rollno marks):skand 46 60

        jang   34   50
           skand   46   60
          akshay   44   55

Enter your choice:3

enter the roll no:44

        jang   34   50
           skand   46   60

Enter your choice:4

enter roll no:34

 found at location=1
jang    34      50

Enter your choice:6

        jang   34   50
          akshay   44   55

Enter your choice:7

enter the rollno:34

Enter data(name rollno marks):jang 34 53






                 */


                                                                               
                                                                               
                                                                               



"C program for Matrix operation"

#include<stdio.h>
#include<conio.h>
void addition();
void substraction();
void multiplication();
void magic_sqr();
void transpose();
void saddle_pt();
int a[10][10],b[10][10],d[10][10],rsum[20],csum[20];
int r1,r2,c1,c2,m,n,i,j,d1,d2,ar,ac,val,flag=0,rowvalue,colvalue;
void main()
{
  int c;
  char ch;
  do
  {
    clrscr();
    printf("\n\n\t MENU");
    printf("\n\n\t 1.Addition");
    printf("\n\n\t 2.Subtraction");
    printf("\n\n\t 3.Multiplication");
    printf("\n\n\t 4.Transpose");
    printf("\n\n\t 5.Saddle Point");
    printf("\n\n\t 6.Magic Square");
    printf("\n\n\t 7.Exit");
    printf("\n\n\t Enter your choice(1,2,3,4,5,6,7):");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:
            addition();
        break;
        case 2:
            substraction();
        break;
        case 3:
            multiplication();
        break;
        case 4:
            transpose();
        break;
        case 5:
            saddle_pt();
        break;
        case 6:
            magic_sqr();
        break;
        case 7:
            exit(0);
        break;
        default:
        printf("\n invalid choice:");
    }
    printf("\n\n\t Do you want to continue in same menu(y/n):");
    c=getch();
  }
  while(c=='y'||c=='Y');
  getch();
}

void addition()
{
   int i,j;
   int d[10][10];
   printf("\n\n\t Enter the size of matrix:");
   scanf("%d%d",&m,&n);
   printf("\n\n\t Enter the elements of first matrix:");
   for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
    {
       scanf("%d",&a[i][j]);
    }
   }
   printf("\n\n\t Enter the elements of second matrix:");
   for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
    {
        scanf("%d",&b[i][j]);
    }
   }
   for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
    {
        d[i][j]=a[i][j]+b[i][j];
    }
   }
   printf("\n\n\t The addition of matrix is:");
   for(i=0;i<m;i++)
   {
    printf("\n\n\t");
    for(j=0;j<n;j++)
    {
        printf("%d\t",d[i][j]);
    }
   }
}

void substraction()
{
  int i,j;
  int d[10][10];
  printf("\n\n\t Enter the size of matrix:");
  scanf("%d%d",&m,&n);
  printf("\n\n\t Enter the elements of first matrix:");
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
    {
        scanf("%d",&a[i][j]);
    }
  }
  printf("\n\n\t Enter the elements of second matrix:");
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
    {
        scanf("%d",&b[i][j]);
    }
  }
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
    {
        d[i][j]=a[i][j]-b[i][j];
    }
  }
  printf("\n\n\t The subtraction of matrix is:");
  for(i=0;i<m;i++)
  {
     printf("\n\n\t");
    for(j=0;j<n;j++)
    {
    printf("%d\t",d[i][j]);
    }
  }
}

void multiplication()
{
  int i,j,k,r1,r2,c1,c2;
  int d[10][10];
  printf("\n\n\t Enter the size of first matrix:");
  scanf("%d%d",&r1,&c1);
  printf("\n\n\t Enter the size of second matrix:");
  scanf("%d%d",&r2,&c2);
  printf("\n\n\t Enter the elements of first matrix:");
  for(i=0;i<r1;i++)
  {
    for(j=0;j<c1;j++)
    {
        scanf("%d",&a[i][j]);
    }
  }
  printf("\n\n\t Enter the elements of second matrix:");
  for(i=0;i<r2;i++)
  {
    for(j=0;j<c2;j++)
    {
        scanf("%d",&b[i][j]);
    }
  }
  if(c1==r2)
  for(i=0;i<r1;i++)
  {
    for(j=0;j<c2;j++)
    {
        d[i][j]=0;
        for(k=0;k<c2;k++)
        {
            d[i][j]=d[i][j]+(a[i][k]*b[k][j]);
        }
    }
  }
  printf("\n\n\t The multiplication is:");
  for(i=0;i<r1;i++)
  {
    printf("\n\n\t");
    for(j=0;j<c2;j++)
    {
        printf("%d\t",d[i][j]);
    }
  }
}

void transpose()
{
  int i,j,m,n;
  int d[10][10];
  printf("\n\n\t Enter the size of matrix:");
  scanf("%d%d",&m,&n);
  printf("\n\n\t Enter the elements of first matrix:");
  for(i=0;i<m;i++)
 {
    for(j=0;j<n;j++)
    {
        scanf("\t%d",&a[i][j]);
    }
 }
 for(i=1;i<m;i++)
 {
    for(j=0;j<i;j++)
    {
        d[i][j]=a[i][j];
        a[i][j]=a[j][i];
        a[j][i]=d[i][j];
    }
 }
 printf("\n\n\t The transepose is:");
 for(i=0;i<m;i++)
 {
    printf("\n\n\t");
    for(j=0;j<m;j++)
    {
        printf("%d\t",a[i][j]);
    }
 }
}

void saddle_pt()
{
  int i,j,small,large,rsmall,clarge,r1,c1,flag=0;
  printf("\n\n\t Enter size of matrix:");
  scanf("%d%d",&r1,&c1);
  printf("\n\n\t Enter the elements of matrix:");
  for(i=0;i<r1;i++)
  {
    for(j=0;j<c1;j++)
    {
        scanf("\t%d",&a[i][j]);
    }
  }
  for(i=0;i<r1;i++)
  {
    rowvalue=a[i][0];
    rsmall=0;
    for(j=1;j<c1;j++)
    {
        if(rowvalue>a[i][j])
        {
            rowvalue=a[i][j];
            rsmall=j;
        }
    }
    colvalue=a[0][rsmall];
    clarge=0;
    for(j=1;j<r1;j++)
    {
        if(colvalue<a[j][clarge])
        {
            colvalue=a[j][rsmall];
            clarge=j;
        }
    }
    if(i==clarge)
    {
        flag=1;
        printf("\n Saddle point is present at(%d ,%d):",i,rsmall);
        printf("\n The element is=%d",a[i][rsmall]);
    }
  }
  if(flag==0)
  {
    printf("\n Saddle point is not present:");
  }
}

void magic_sqr()
{
   printf("\n\n\t Enter size of matrix:");
   scanf("%d%d",&r1,&c1);
   printf("\n\n\t Enter the elements of matrix:");
   for(i=0;i<r1;i++)
   {
    for(j=0;j<c1;j++)
    {
        scanf("%d",&a[i][j]);
    }
    }
   if(r1==c1)
   {
    for(i=0;i<c1;i++)
    {
        for(j=0;j<c1;j++)
        {
            rsum[i]=rsum[i]+a[i][j];
        }
    }
    for(i=0;i<r1;i++)
    {
        for(j=0;j<c1;j++)
        {
            csum[i]=csum[i]+a[i][j] ;
        }
    }
   }
   for(i=0;i<r1;i++)
   {
    for(j=0;j<r1;j++)
    {
        if(i==j)
        d1=d1+a[i][j];
    }
   }
   for(i=0;i<r1;i++)
   {
    for(j=r1-1;j>=0;j--)
    {
        if(i==j)
        {
            d2=d2+a[i][j];
        }
    }
   }
   ar=rsum[0];              //
   for(i=0;i<r1;i++)
   {
    if(ar!=rsum[i])
    flag=1;
   }
   ac=csum[0];
   for(i=0;i<r1;i++)
   {
    if(ac!=csum[i])
    flag=1;
   }
   if(d1==d2&& ar==ac &&flag==0&&d1==ac)
   {
    printf("\n\n\t Matrix is magic square:");
   }
   else
   {
    printf("\n\t Not Magic square:");
   }
}

/*
OUTPUT:-

     MENU

     1.Addition

     2.Subtraction

     3.Multiplication

     4.Transpose

     5.Saddle Point

     6.Magic Square

     7.Exit

     Enter your choice(1,2,3,4,5,6,7):1


     Enter the size of matrix:2 3


     Enter the elements of first matrix:1
2 3 4 5 6


     Enter the elements of second matrix:1 2 3 4 5 6


     The addition of matrix is:

    2       4       6

    8       10      12



    Enter your choice(1,2,3,4,5,6,7):2


     Enter the size of matrix:2 2


     Enter the elements of first matrix:1 2 3 4


     Enter the elements of second matrix:1 2 3 4


     The subtraction of matrix is:

    0       0

    0       0






     Enter your choice(1,2,3,4,5,6,7):3


     Enter the size of first matrix:2 2


     Enter the size of second matrix:1 2 3 4


     Enter the elements of first matrix:1 2 3 4


     Enter the elements of second matrix:

     The multiplication is:

        7   10

        15  22




     Enter your choice(1,2,3,4,5,6,7):4


     Enter the size of matrix:2 2


     Enter the elements of first matrix:1 2 3 4


     The transepose is:

    1       3

    2       4


     Enter your choice(1,2,3,4,5,6,7):5


     Enter size of matrix:2 2


     Enter the elements of matrix:1 2 3 4

 Saddle point is present at(1 ,0):
 The element is=3



     Enter your choice(1,2,3,4,5,6,7):6


     Enter size of matrix:2 2


     Enter the elements of matrix:1 1 1 1


     Matrix is magic square:



*/







                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               





































                                                                               
                                                                               
                                                                               
                                                                               
                                              

                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                          







                                                                               











































































                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               






   

Few Linux App & commands which is going to used to Build AOSP(Android Open Source Project) Source Code

1. sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32n...