Tuesday, July 2, 2013

4:1 MULTIPLEXER IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    15:19:42 03/09/2013
-- Design Name:
-- Module Name:    ANIMULTIPLEXER - Behavioral
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date:    22:02:51 05/12/2013
-- Design Name:
-- Module Name:    ANIMULTIPLEXER4TO1 - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity ANIMULTIPLEXER4TO1 is
    Port ( IO : in  STD_LOGIC;
           I1 : in  STD_LOGIC;
           I2 : in  STD_LOGIC;
           I3 : in  STD_LOGIC;
           SEL : in  STD_LOGIC_VECTOR (1 downto 0);
           O : out  STD_LOGIC);
end ANIMULTIPLEXER4TO1;

architecture Behavioral of ANIMULTIPLEXER4TO1 is

begin

PROCESS(IO,I1,I2,I3,SEL)
BEGIN
CASE SEL IS
WHEN "00" => O<=IO;
WHEN "01" => O<=I1;
WHEN "10" => O<=I2;
WHEN OTHERS => O<=I3;
END CASE;
END PROCESS;

end Behavioral;

OR GATE IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    15:34:56 02/23/2013
-- Design Name:
-- Module Name:    ANI_OR_GATE - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANI_OR_GATE is
    Port ( a : in  STD_LOGIC;
           b : in  STD_LOGIC;
           c : out  STD_LOGIC);
end ANI_OR_GATE;
architecture Behavioral of ANI_OR_GATE is
begin
c<=a OR b;
end Behavioral;

NAND GATE IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    15:50:17 02/23/2013
-- Design Name:
-- Module Name:    ANI_NAND - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANI_NAND is
    Port ( A : in  STD_LOGIC;
           B : in  STD_LOGIC;
           C : out  STD_LOGIC);
end ANI_NAND;
architecture Behavioral of ANI_NAND is
begin
C <= A NAND B;
end Behavioral;

HALF SUBTRACTOR IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    14:36:46 04/06/2013
-- Design Name:
-- Module Name:    ANIHS - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANIHS is
    Port ( A : in  STD_LOGIC;
           Bin : in  STD_LOGIC;
           Bout : out  STD_LOGIC;
           D : out  STD_LOGIC);
end ANIHS;
architecture Behavioral of ANIHS is
begin
D <= A XOR Bin;
Bout <= (NOT A) AND Bin;
end Behavioral;

HALF ADDER IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    16:30:51 02/23/2013
-- Design Name:
-- Module Name:    ANI_HA - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANI_HA is
    Port ( A : in  STD_LOGIC;
           B : in  STD_LOGIC;
           C : out  STD_LOGIC;
           S : out  STD_LOGIC);
end ANI_HA;
architecture Behavioral of ANI_HA is
begin
S <= A OR B;
C <= A AND B;
end Behavioral;

FULL SUBTRACTOR IN XILINX ISE 9.1i

-- Company:
-- Engineer:
--
-- Create Date:    14:52:14 04/06/2013
-- Design Name:
-- Module Name:    ANIFS - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANIFS is
    Port ( A : in  STD_LOGIC;
           Bin : in  STD_LOGIC;
           C : in  STD_LOGIC;
           D : out  STD_LOGIC;
           Bout : out  STD_LOGIC);
end ANIFS;
architecture Behavioral of ANIFS is
begin
D <= A XOR (Bin XOR C);
Bout <= (((NOT A) AND (Bin XOR C)) OR (Bin AND C));
end Behavioral;

FULL ADDER IN XILINX ISE 9.1i




-- Company:
-- Engineer:
--
-- Create Date:    15:39:58 03/02/2013
-- Design Name:
-- Module Name:    ANIFA - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ANIFA is
    Port ( A : in  STD_LOGIC;
           B : in  STD_LOGIC;
           C : in  STD_LOGIC;
           S : out  STD_LOGIC;
           Co : out  STD_LOGIC);
end ANIFA;
architecture Behavioral of ANIFA is
begin
S <= (A XOR B) XOR C;
Co <= (A AND B) OR (C AND (A XOR B));
end Behavioral;

C PROGRAM FOR WEDDLE'S RULE

/*PROGRAM FOR WEDDLE'S RULE*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float);
 float f(float x)
  {     float y;
        y=1/(1+x*x);
        return(y); }                        
void main() {
      float a,b,h,s1=0,s2=0,s=0;
      int i,n,m;
      clrscr();
      printf("Enter the value of upper limit= ");
      scanf("%f",&b);
       printf("Enter the value of lower limit= ");
      scanf("%f",&a);
       printf("Enter the value of n=");
      scanf("%d",&n);
      h=(b-a)/n;
      printf("h= %f",h);
      m=n/6;
      s=0;
      if(n%6==0) {
      for(i=1;i<=m;i++){
          s=s+((3*h/10)*(f(a)+f(a+2*h)+5*f(a+h)+6*f(a+3*h)+f(a+4*h)+5*f(a+5*h)+f(a+6*h)));
          a=a+6*h;  }
          printf("\nResult is : %f",s);}
          else {
              printf(" Weddle’s rule is not applicable");}      
              getch();
 }

/*OUTPUT:-
Enter the value of upper limit= 6
Enter the value of lower limit= 0
Enter the value of n=6
h= 1.000000
Result is : 1.373448  */

C PROGRAM FOR TRAPEZOIDAL RULE OF NUMERICAL INTEGRATION

/*PROGRAM FOR TRAPEZOIDAL RULE OF NUMERICAL INTEGRATION*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(X)  (4*X-(3*(X*X)))
void main() {
int i,n;
float a,b,h,x[20],y[20],j;
clrscr();
printf("Enter upper limit,lower limit & sub interval:");
scanf("%f %f %d",&a,&b,&n);
x[0]=b;
h=(a-b)/n;
for(i=0;i<=n;i++) {
      y[i]=f(x[i]);
      x[i+1]=x[i] + h;
}
j=y[0];
for(i=0;i<=n-1;i++)
j=j + ((h/2) * (y[i]+y[i+1]));
printf("The required value is=%f ", j);
getch();
}
/*OUTPUT:-
Enter upper limit,lower limit & sub interval:1
0
10
The required value is=0.995000  */

C PROGRAM FOR SIMPSON'S 1/3rd RULE OF NUMERICAL INTEGRATION

/*PROGRAM FOR SIMPSON'S 1/3rd RULE OF NUMERICAL INTEGRATION*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(X)  (4*X-(3*(X*X)))
void main() {
int i,n;
float a,b,h,x[20],y[20],j;
clrscr();
printf("Enter upper limit,lower limit & sub interval:");
scanf("%f %f %d",&a,&b,&n);
x[0]=b;
h=(a-b)/n;
for(i=0;i<=n;i++) {
      y[i]=f(x[i]);
      x[i+1]=x[i] + h;
}
j=y[0];
for(i=0;i<=n-2;i+=2)
j=j + ((h/3) * (y[i]+4*y[i+1]+y[i+2]));
printf("The required value is=%f ", j);
getch();
}

/*OUTPUT:-
Enter upper limit,lower limit & sub interval:1
0
10
The required value is=1.000000  */

C PROGRAM FOR NEWTON RAPHSON METHOD

/* PROGRAM FOR NEWTON RAPHSON METHOD*/
#include<stdio.h>
#include<math.h>
#include<conio.h>
{ double f(double), f1(double)
   double x[100];            
                 }


main() {
       float a[20][20],ratio,x[20];
       int i,j,k,n;
       clrscr();
       printf("\n Enter order of matrix:");
       scanf("%d", &n);
       printf("Enter the coefficients & RHS \n");
       for(i=1;i<=n;i++){
          for(j=1;j<=n+1;j++)
          scanf("%f", &a[i][j]);
          printf("\n"); }
       for(k=1;k<=n-1;k++){
          for(i=k+1;i<=n;i++){
                  ratio=a[i][k]/a[k][k];
                  for(j=1;j<=n+1;j++)
                  a[i][j] = a[i][j] - ratio * a[k][j];}}
                  x[n]=a[n][n+1]/a[n][n];                            
       for(k=n-1;k>=1;k--){
         x[k] = a[k][n+1];
         for(j = k+1;j<=n;j++)
         x[k] = x[k]-a[k][j] * x[j];
         x[k]= x[k]/a[k][k];}
       for(i=1;i<=n;i++)
         printf("\n x(%d)=%g",i,x[i]);                
       getch();
       }

C PROGRAM FOR NEWTON FORWARD DIFFERENCE FORMULA FOR INTERPOLATION

/*PROGRAM FOR NEWTON FORWARD DIFFERENCE FORMULA FOR INTERPOLATION */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i,n,j,fact=1;
float x[20],y[20][20],h,d=1,p,a,f;
clrscr();
printf("Enter The Value of n:");
scanf("%d",&n);
printf("\nEnter the elements of x:");
for(i=1;i<=n;i++)
scanf("%f", &x[i]);
printf("\nEnter The Elements of y:");
for(i=1;i<=n;i++)
scanf("%f",&y[i][1]);
h=x[2]-x[1];
printf("Enter x for which y is to be calculated:");
scanf("%f",&f);
p = (f-x[1])/h;
a=y[1][1];
for(j=2;j<=n;j++) {
for(i=1;i<=(n-j)+1;i++)
y[i][j]= y[i+1][j-1] - y[i][j-1];
}
printf("The Table is :\n\n");
for(i=1;i<=n;i++)
    {
printf("\t%.2f",x[i]);
for(j=1;j<=(n-i)+1;j++)
   printf("\t%.2f",y[i][j]);
printf("\n");
    }
for(j=2;j<=n;j++) {
for(i=1;i<j;i++)
fact=fact*i;

d = d*(p-(j-1));
a = a + (y[1][j]*d)/fact;
fact=1;
}
printf("\n\nFor x=%f The Value of y is %f",f,a);
getch();
}

/* OUTPUT:-
Enter The Value of n:4

Enter the elements of x:0
1
2
3

Enter The Elements of y:1
0
1
10
Enter x for which y is to be calculated:4
The Table is :

        0.00    1.00    -1.00   2.00    6.00
        1.00    0.00    1.00    8.00
        2.00    1.00    9.00
        3.00    10.00


For x=4.000000 The Value of y is 10.000000  */

C PROGRAM FOR NEWTON BACKWARD DIFFERENCE FORMULA FOR INTERPOLATION

/*PROGRAM FOR NEWTON BACKWARD DIFFERENCE FORMULA FOR INTERPOLATION */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i,n,j,fact=1;
float x[20],y[20][20],h,d=1,p,a,f;
clrscr();
printf("Enter The Value of n:");
scanf("%d",&n);
printf("\nEnter the elements of x:");
for(i=1;i<=n;i++)
scanf("%f", &x[i]);
printf("\nEnter The Elements of y:");
for(i=1;i<=n;i++)
scanf("%f",&y[i][1]);
h=x[2]-x[1];
printf("Enter x for which y is to be calculated:");
scanf("%f",&f);
p = (f-x[n])/h;
a=y[n][1];
for(j=2;j<=n;j++) {
for(i=n;i>=1;i--)
y[i][j]= y[i][j-1] - y[i-1][j-1];
}
printf("The Table is :\n\n");
for(i=1;i<=n;i++)
    {
printf("\t%.2f",x[i]);
for(j=1;j<=i;j++)
   printf("\t%.2f",y[i][j]);
printf("\n");
    }
for(j=2;j<=n;j++) {
for(i=1;i<j;i++)
fact=fact*i;

d = d*(p+(j-2));
a = a + (y[n][j]*d)/fact;
fact=1;
}
printf("\n\nFor x=%f The Value of y is %f",f,a);
getch();
}

/* OUTPUT:-
Enter The Value of n:5

Enter the elements of x:.1
.2
.3
.4
.5

Enter The Elements of y:.09
.19
.29
.38
.47
Enter x for which y is to be calculated:.15
The Table is :

        0.10    0.09
        0.20    0.19    0.10
        0.30    0.29    0.10    0.00
        0.40    0.38    0.09    -0.01   -0.01
        0.50    0.47    0.09    0.00    0.01    0.02


For x=0.150000 The Value of y is 0.138594       */

C PROGRAM FOR LAGRANGE'S INTERPOLATION FORMULA

/*PROGRAM FOR LAGRANGE'S INTERPOLATION FORMULA*/

#include<stdio.h>
#include<conio.h>
void main () {
  int i,j, n;
  float x[20],y[20], p[20],f,k=0;
  clrscr();
  printf("Enter the number of terms:");
  scanf("%d",&n);
  printf("Enter the values of:\nx y\n");
  for(i=0;i<n;i++) {
  scanf("%f %f",&x[i], &y[i]);
  }
  printf("Enter value of x for which y is to be found:");
  scanf("%f",&f);
  for(j=1;j<=n;j++) {
  p[j]=1.0;
  for(i=1;i<=n;i++) {
  if(i==j)
  continue;
  p[j]=p[j] * (f-x[i])/(x[j]-x[i]);
  }
  }
  for(i=1;i<=n;i++)
  k = k + p[i]* y[i];
  printf("for x = %f, y = %f",f,k);

getch();
}

/*OUTPUT:-
Enter the number of terms:4
Enter the values of:
x       y
5       12
6       13
9       14
11      16
Enter value of x for which y is to be found:10
for x = 10.000000, y = 14.744108   */

C PROGRAM FOR GAUSS ELIMINATION METHOD

/* PROGRAM FOR GAUSS ELIMINATION METHOD*/
#include<stdio.h>
#include<conio.h>
void main() {
       float a[20][20],ratio,x[20];
       int i,j,k,n;
       clrscr();
       printf("\n Enter order of matrix:");
       scanf("%d", &n);
       printf("Enter the coefficients & RHS \n");
       for(i=1;i<=n;i++){
          for(j=1;j<=n+1;j++)
          scanf("%f", &a[i][j]);
          printf("\n"); }
       for(k=1;k<=n-1;k++){
          for(i=k+1;i<=n;i++){
                  ratio=a[i][k]/a[k][k];
                  for(j=1;j<=n+1;j++)
                  a[i][j] = a[i][j] - ratio * a[k][j];}}
                  x[n]=a[n][n+1]/a[n][n];                            
       for(k=n-1;k>=1;k--){
         x[k] = a[k][n+1];
         for(j = k+1;j<=n;j++)
         x[k] = x[k]-a[k][j] * x[j];
         x[k]= x[k]/a[k][k];}
       for(i=1;i<=n;i++)
         printf("\n x(%d)=%g",i,x[i]);                
       getch();
       }

/*OUTPUT:-
Enter order of matrix:4
Enter the coefficients & RHS
2       2       1       2       7

-1      2       0       1       -2

-3      1       2       1       -3

-1      0       0       2       0


 x(1)=2.16216
 x(2)=-0.45946
 x(3)=1.43243
 x(4)=1.08108 */

C PROGRAM TO FIND THE MAXIMUM VALUE USING ARRAY

\* PROGRAM TO FIND THE MAXIMUM VALUE USING ARRAY*\

#include<stdio.h>
#include<conio.h>
void main() {
int a[155],n,i,max;
               clrscr();
printf("Enter No. of items:");
scanf("%d", &n);
for(i=0;i<n;i++)
{ printf("Enter value a[%d]", i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
printf("\t%d", a[i]);
}
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
max=a[i];
}
   printf("\nMaximum value is %d", max);
getch();
}



\*OUTPUT:
         
Enter No. of items:4
Enter value a[0]5
Enter value a[1]7
Enter value a[2]99
Enter value a[3]656
        5       7       99      656
Maximum value is 656  *\

C PROGRAM FOR STACK

/*PROGRAM TO MAKE A STACK TEST PUSH & POP OPERATION IN A STACK*/
#include<stdio.h>
#include<conio.h>
#define max 5
void PUSH();
void POP();
void DISPLAY();
int a[max], item, i, v, top=-1, n;
void main()
{
clrscr();
do {
printf("\nChoice are:");
printf("\n1: PUSH");
printf("\n2: POP");
printf("\n3: DISPLAY ITEMS");
printf("\n4: EXIT");
printf("\nEnter your choice:");
scanf("%d", &n);
switch(n) {
case 1: { PUSH();
break; }
case 2: { POP();
    break; }
case 3: { DISPLAY();
break; }
}
}
while (n!=4);
}

void PUSH() {
if(top==max-1)
printf("\nSTACK OVERFLOW\n");
else {
top=top+1;
printf("\nEnter pushing value:");
scanf("%d", &v);
a[top] = v; }
}
void POP() {
if(top==-1)
printf("\nSTACK UNDERFLOW\n");
else {
item = a[top];
printf("The poped item is %d", item);
top= top-1; }
}
void DISPLAY() {
printf("\nThe items in the STACK are:");
for(i=0;i<=top;i++)
printf(" %d " , a[i]); }





/*OUTPUT:-

Choice are:
1: PUSH
2: POP
3: DISPLAY ITEMS
4: EXIT
Enter your choice:1

Enter pushing value:30

Choice are:
1: PUSH
2: POP
3: DISPLAY ITEMS
4: EXIT
Enter your choice:3

The items in the STACK are: 30
Choice are:
1: PUSH
2: POP
3: DISPLAY ITEMS
4: EXIT
Enter your choice:2
The poped item is 30
Choice are:
1: PUSH
2: POP
3: DISPLAY ITEMS
4: EXIT
Enter your choice:4 */

C PROGRAM FOR LINEAR QUEUE

/*PROGRAM TO TEST INSERTION & DELETION OPERATION IN LINEAR QUEUE*/
#include<stdio.h>
#include<conio.h>
void main() {
int max=5, n, r=0, f=0, a[5], v, item, i;
clrscr();
do {
printf("\nChoice are:");
printf("\n1: INSERTION");
printf("\n2: DELETION");
printf("\n3: DISPLAY ITEMS");
printf("\n4: EXIT");
printf("\nEnter your choice:");
scanf("%d", &n);
switch(n) {
case 1: {
 if(r==max)
 printf("\nQUEUE REACHED LIMIT\n");
 else {
 printf("\nEnter insertion value:");
 scanf("%d", &v);
 a[r]=v;
 r++; }
 break;
}
case 2: { if(f==r)
 printf("\nQUEUE IS EMPTY");
 else {
 item=a[f];
 f++;
 printf("\nDeleted item is: %d", item); }
 break;
}
case 3: { printf("\nThe items in the QUEUE are:");
 for(i=f;i<r;i++)
 printf(" %d ", a[i]);
 break; }
}
}
while(n!=4);
}
















/*OUTPUT:-

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:1

Enter insertion value:1

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:1

Enter insertion value:2

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:3

The items in the QUEUE are: 1  2
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:2

Deleted item is: 1
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:3

The items in the QUEUE are: 2
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:4   */

C PROGRAM FOR INSERTION, DELETION TESTING IN AN ARRAY USING FUNCTION

/*PROGRAM FOR INSERTION, DELETION TESTING IN AN ARRAY USING FUNCTION*/

#include<stdio.h>
#include<conio.h>
int b,c,d,n,i,j,v,p,m,x;
int a[100];
void insertion();
void deletion();
void main() {
clrscr();
printf("Enter array size:");
scanf("%d", &n);
printf("\nEnter values of array:\n");
for(b=0;b<n;b++) {
scanf("%d", &a[b]);
x=b+1; }
do {
printf("\nChoices are:\n");
printf("1: Insertion\n");
printf("2: Deletion\n");
printf("3: Display\n");
printf("4: Exit\n");
printf("\nEnter Your Choice:\n");
scanf("%d", &c);
switch(c) {
case 1: {
insertion();
break; }
case 2: {
deletion();
break; }
case 3: {
printf("\nThe values in the array are:");
for(d=0;d<x;d++)
printf(" %d ", a[d]);
break; }
}
}
while(c!=4);
getch();
}

void insertion() {
if(x!=n) {
printf("\nEnter insertion position 0 to n:(Enter 0 if array is empty and so on in serial number pattern):");
scanf("%d", &p);
printf("\nEnter insertion value:");
scanf("%d", &v);
for(i=x-1;i>=p;i--)
a[i+1]= a[i];
a[p]= v;
x=x+1; }
else
printf("Array is full"); }

void deletion() {
if(x!=0) {
printf("\nEnter deletion Position 0 to n:");
scanf("%d", &m);
for(j=m;j<n-1;j++)
a[j]= a[j+1];
x=x-1; }
else
printf("Array is empty"); }


/*OUTPUT:
       
Enter array size:3

Enter values of array:
1
2
3

Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
3

The values in the array are: 1  2  3
Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
2

Enter deletion Position 0 to n:1

Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
3

The values in the array are: 1  3
Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
1

Enter insertion position 0 to n:(Enter 0 if array is empty and so on in serial number pattern):1

Enter insertion value:9

Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
3

The values in the array are: 1  9  3
Choices are:
1: Insertion
2: Deletion
3: Display
4: Exit

Enter Your Choice:
4*/

C PROGRAM FOR CIRCULAR QUEUE

/*PROGRAM TO TEST INSERTION & DELETION OPERATION IN CIRCULAR QUEUE*/
#include<stdio.h>
#include<conio.h>
#define max 5
int front,rear,q[max];
void inqueue();
void delqueue();
void qdisplay();
int main() {
int c;
clrscr();
front=rear=-1;
do {
printf("\n1:INSERTION \n2:DELETION\n3:DISPLAY ");
printf("\n4:EXIT\nEnter Your Choice:");
scanf("%d",&c);
switch(c) {
case 1: {inqueue ();
break; }
case 2: {delqueue ();
break; }
case 3: {qdisplay ();
break; }
}
}
while(c!=4);
}

void inqueue() {
int x;
if ((front==0&&rear==max-1)|| (front==rear+1))
{ printf("\nQUEUE OVERFLOW\n");
return; }
if(front==-1)
{ front=rear=0; }
else
{ if(rear==max-1)
{ rear=0; }
else { rear++; } }
printf("\nEnter The Number:");
scanf("%d",&x);
q[rear]=x;
return; }

void delqueue() {
int y;
if(front==-1) {
printf("\nQUEUE IS UNDERFLOW \n");
return; }
y=q[front];
if(front==rear)
{ front=rear=-1; }
else
{ if(front==max-1)
{ front=0; }
else
{ front++; } }
printf("\n%d SUCESSFULLY DELETED \n",y);
return; }

void qdisplay() {
int i,j;
if(front==rear==-1)
{ printf("\nQUEUE IS EMPTY \n");
return; }
printf("\nITEMS ARE:");
for(i=front;i!=rear;i=(i +1)%max)
{ printf(" %d ",q[i]); }
printf(" %d ",q[rear]);
return; }





/************************************************************/
/*OUTPUT:-\

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:1

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:2

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:3

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:4

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:5

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

QUEUE OVERFLOW

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:3

ITEMS ARE: 1  2  3  4  5
1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:2

1 SUCESSFULLY DELETED

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:3

ITEMS ARE: 2  3  4  5
1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:1

Enter The Number:7

1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:3

ITEMS ARE: 2  3  4  5  7
1:INSERTION
2:DELETION
3:DISPLAY
4:EXIT
Enter Your Choice:4 */

C PROGRAM FOR 2D MATRIX MULTIPLICATION

/*PROGRAM TO MULTIPLY TWO MATRICES*/

#include<stdio.h>
#include<conio.h>
void main() {
int i,j,k,m,n,o,p,sum=0;
int a[10][10],b[10][10],c[10][10];
clrscr();
printf("Enter order of 1st 2D matrix:");
scanf("%d %d",&m,&n);
printf("Enter order of 2nd 2D matrix");
scanf("%d %d",&o,&p);
if(n==o){
printf("Enter elements of 1st 2d matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
                  printf("\na[%d][%d]=", i,j);
                  scanf("%d", &a[i][j]);
                  }
printf("Enter elements of 2nd 2D matrix:");
for(i=1;i<=o;i++)
for(j=1;j<=p;j++){
                  printf("\nb[%d][%d]=", i,j);
                  scanf("%d", &b[i][j]);
                  }
printf("\nThe product of two matrices has these elements:");
for(i=1;i<=m;i++)
for(j=1;j<=p;j++){
                  for(k=1;k<=n;k++)
                  sum=sum+a[i][k]*b[k][j];
                  c[i][j]=sum;
                  sum=0;
                  printf("\nc[%d][%d]=%d", i,j,c[i][j]);
                  }                
}
else
printf("The matrices cannot be multiplied");
getch();
}

/* OUTPUT:-
Enter order of 1st 2D matrix:1
2
Enter order of 2nd 2D matrix2
3
Enter elements of 1st 2d matrix:
a[1][1]=1

a[1][2]=2
Enter elements of 2nd 2D matrix:
b[1][1]=3

b[1][2]=4

b[1][3]=5

b[2][1]=6

b[2][2]=7

b[2][3]=8

The product of two matrices has these elements:
c[1][1]=15
c[1][2]=18
c[1][3]=21  */

C PROGRAM FOR 2D MATRIX ADDITION

/* PROGRAM TO ADD TWO MATRICES*/

#include<stdio.h>
#include<conio.h>
void main() {
int i,j,m,n;
int a[5][5],b[5][5],c[10][10];
clrscr();
printf("Enter size of 2D arrays:");
scanf("%d %d",&m,&n);
printf("Enter elements of 1st 2d matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
                  printf("\na[%d][%d]=", i,j);
                  scanf("%d", &a[i][j]);
                  }
printf("Enter elements of 2nd 2D matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
                  printf("\nb[%d][%d]=", i,j);
                  scanf("%d", &b[i][j]);
                  }
printf("\nThe sum of two matrix has these elements:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
                  c[i][j]=a[i][j]+b[i][j];
                  printf("\nc[%d][%d]=%d", i,j,c[i][j]);
                  }                
getch();
}

/* OUTPUT:-
Enter size of 2D arrays:1
2
Enter elements of 1st 2d matrix:
a[1][1]=1

a[1][2]=2
Enter elements of 2nd 2D matrix:
b[1][1]=1

b[1][2]=5

The sum of two matrix has these elements:
c[1][1]=2
c[1][2]=7  */