Experiment No: 8 Aim:: Jashandeep Singh 110913051 ECE-01
Experiment No: 8 Aim:: Jashandeep Singh 110913051 ECE-01
Experiment No: 8 Aim:: Jashandeep Singh 110913051 ECE-01
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,temp;
clrscr();
printf("enter the 5 elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
if(a[i]>a[j])
{temp=a[i];
a[i]=a[j];
JASHANDEEP SINGH
110913051
ECE-01
a[j]=temp;
}
}
}
printf("sorted arry\n");
for(i=0;i<5;i++)
printf("%d\n",a[i]);
getch();
}
JASHANDEEP SINGH
110913051
ECE-01
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01
EXPERIMENT NO: 12
AIM: Write a program toImplement stack using array.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
int top=0,a[10];
void in()
{ charans='n';
do
{ printf("enter the no");
scanf("%d",&a[top]);
top++;
fflush(stdin);
printf("want to enter:");
scanf("%c",&ans);
}while(ans=='y');
JASHANDEEP SINGH
110913051
ECE-01
}
void del()
{ charans='n';
do
{ printf("no del ");
top--;
fflush(stdin);
printf("want to del more:");
scanf("%c",&ans);
}while(ans=='y');
}
void display()
{ inti;
for(i=0;i<top;i++)
printf("%d\n",a[i]);
}
void main()
{
clrscr();
in();
del();
display();
JASHANDEEP SINGH
110913051
ECE-01
getch();
}
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01
EXPERIMENT NO: 10
AIM: Write a programto sort the given array using
insertion sort.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
void main()
{intsize,a[13],i,j=0,temp=0;
clrscr();
printf("enter size : ");
scanf("%d",&size);
printf("\nenter element in arry");
for(i=0;i<size;i++)
scanf("%d",&a[i]);
JASHANDEEP SINGH
110913051
ECE-01
for(i=0;i<size;i++)
{ for(j=1;j<size-1;j++)
{ if(a[i]>a[j+1]&a[i]<a[j+2])
{temp=a[i];
a[i]=a[j+1];
a[j+1]=temp;
}
}
for(i=0;i<size;i++)
printf(" %d ",a[i]);
getch();
}
JASHANDEEP SINGH
110913051
ECE-01
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01
EXPERIMENT NO: 11
AIM: Write a programto sort the given array using
selection sort.
SOURCE CODE :
#include<conio.h>
#include<stdio.h>
void main()
{int a[12],size,i,j=0,temp=0,loc;
clrscr();
printf("Enter size of array");
scanf("%d",&size);
printf("enter in arry");
JASHANDEEP SINGH
110913051
ECE-01
for(i=0;i<size;i++)
scanf("%d",&a[i]);
while(j<size-1)
{loc =j;
for(i=j+1;i<size;i++)
{
if(a[j]<a[i])
loc=i;
}
temp=a[loc];
a[loc]=a[j];
a[j]=temp;
j++;
}
for(i=0;i<size;i++)
printf(" %d ",a[i]);
getch();
}
JASHANDEEP SINGH
110913051
ECE-01
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01
JASHANDEEP SINGH
110913051
ECE-01
EXPERIMENT NO: 9
AIM:Write a programtoImplement queues using array.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
int rear=0,front=0,a[10],size=10;
void in()
{ charans='n';
do
{ printf("enter the no");
scanf("%d",&a[rear]);
rear++;
fflush(stdin);
printf("want to enter:");
scanf("%c",&ans);
}while(ans=='y');
}
void del()
JASHANDEEP SINGH
110913051
ECE-01
{ charans='n';
do
{ printf("no del");
front++;
fflush(stdin);
printf("want to del more:");
scanf("%c",&ans);
}while(ans=='y');
}
void display()
{ inti;
for(i=front;i<rear;i++)
printf("%d\n",a[i]);
}
void main()
{int a;
clrscr();
in();
del();
display();
getch();
JASHANDEEP SINGH
110913051
ECE-01
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01
EXPERIMENT NO: 6
AIM: Write a program to implement various operation
on string.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
inti,j,n,len;
char str1[50],str2[50];
clrscr();
printf("enter the string");
gets(str1);
len=strlen(str1);
printf("\nlength of string is:%d",len);
strrev(str1);
JASHANDEEP SINGH
110913051
ECE-01
JASHANDEEP SINGH
110913051
ECE-01
OUTPUT:
JASHANDEEP SINGH
110913051
ECE-01