Ds File Original
Ds File Original
Program file
#include<string.h>
void main()
char s[999],t[999];
clrscr();
scanf("%s",&s);
strcpy(t,s);
strrev(t);
if(strcmp(s,t)==0)
printf("pallindrome");
else
printf("non pallindrome");
getch();
}
OUTPUT :
Case 1.
pallindrome
Case 2.
non pallindrome
Programe for Linear Search in array.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int n,i,item,a[100];
clrscr();
scanf("%d",&n);
for(i=0;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&item);
for(i=0;i<=n;i++)
{
if(a[i]==item)
break;
if(a[i]!=item)
getch();
OUTPUT :
enter the no. of elements of array 3
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int n,k,a[100]={1,2,3,4},i,item;
clrscr();
printf("\n enter the no of elements of array");
scanf("%d",&n);
printf("enter the location k");
scanf("%d",&k);
for(i=n;i>=k;i--)
{
a[i+1]=a[i];
}
printf("\n enter the item");
scanf("%d",&item);
a[k]=item;
n=n+1;
printf("array is");
for(i=0;i<=n;i++)
{
printf("\n a[%d]=%d",i,a[i]);
}
getch();
}
OUTPUT :
OUTPUT :
enter the no. of elements 5
enter the array 84
74
98
2
6
74
array is
a[0]=2
a[0]=6
a[0]=74
a[0]=74
a[0]=84
a[0]=98
Program for Binary Search in array.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int beg,n,end,mid,i,item,a[100];
clrscr();
printf("enter the no. of elements of array");
scanf("%d",&n);
beg=0;
end=n;
mid=(beg+end)/2;
printf("\n enter the elements of array");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("\n enter the item");
scanf("%d",&item);
while(beg<=end&&a[mid]!=item)
{
if(item<a[mid])
{
end=mid-1;
}
else
{
beg=mid+1;
}
mid=(beg+end)/2;
}
if(a[mid]==item)
{
printf("\n item is found at location = %d",mid+1);
}
else
{
printf("\n item not found so location = NULL");
}
getch();
}
OUTPUT :