Saturday, December 18, 2021
Tuesday, November 16, 2021
Wednesday, October 20, 2021
Program 3- Linear Search in C Language
***********************************************
#include
<stdio.h>
int
main()
{
int a[20],i,x,n, c;
printf("How many elements you are
going to enter?");
scanf("%d",&n);
printf("Enter array elements:");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
printf("\n Enter element to
search:");
scanf("%d",&x);
for(i=0;i<n;++i)
if(a[i]==x)
{ printf("Element %d found at
index %d \n",x, i);
c=c+1;
}
if(c>0)
printf("Element %d found %d times
",x, c);
else
printf("Element not found");
return 0;
Program 2- Selection Sort in C Language
****************************************************
#include
<stdio.h>
int
main()
{ int i, j, n, temp, arr[25];
printf("How many numbers u are going to
enter?: ");
scanf("%d",&n);
printf("Enter %d elements: ", n);
// Loop to
get the elements stored in array
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
// Logic of
selection sort algorithm
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i<n;i++)
printf(" %d",arr[i]);
return 0;
}
Program 1- Insertion Sort in C language
***************************************************