Showing posts with label Push. Show all posts
Showing posts with label Push. Show all posts

Friday, 24 May 2013

POP operation on stack


#include<stdio.h>
#include<conio.h>
void main()
{
int stack[10]={1,2,3,4,5};
int i,n,item,top=4;
do
{
if(top<0)
{
printf("Underflow");
getch();
break;
}
else
{
top=top-1;
printf("\n\nStack elements are");
for(i=top;i>=0;i--)
{
printf("\n%d",stack[i]);
}
}
printf("\n\nDo you want to delete more elements from stack(1 for yes 2 for no)");
scanf("%d",&n);
}
while(n==1);
}

PUSH Operation on stack


#include<stdio.h>
#include<conio.h>
void main()
{
int stack[10];
int i,n,max=9,top=-1,item;
clrscr();
do
{
if(top==max)
{
 printf("\nOVERFLOW");
 printf("Press any key to continue");
 getch();
 break;
}
else
{
 top=top+1;
 printf("Enter the element to be inserted");
 scanf("%d",&item);
 stack[top]=item;
 printf("Stack elements are");
 for(i=top;i>=0;i--)
 {
 printf("\n%d",stack[i]);
 }
}
printf("\n\nDo you want to insert more element(Press 1 for Yes 2 for No");
scanf("%d",&n);
}
while(n==1);
}

Multiplication of two matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],mul[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\nMultiplication of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
mul[i][j]=a[i][j]*b[i][j];
printf("\na[%d][%d] = %d ",i,j,mul[i][j]);

}
printf("\n");
}

getch();
}

Diffference of two matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],diff[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\ndiffrence of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
diff[i][j]=a[i][j]-b[i][j];
printf("\na[%d][%d] = %d ",i,j,diff[i][j]);

}
printf("\n");
}

getch();
}

Addition of two Matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],sum[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\nSum of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("\na[%d][%d] = %d ",i,j,sum[i][j]);

}
printf("\n");
}

getch();
}
                               
full details in json
Proudly Powered by Blogger.
back to top