Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Examples of Sorting and Searching using c language

Rating
-
Sold
-
Pages
7
Uploaded on
06-10-2023
Written in
2023/2024

Linear search,linear sorting,bubble sorting,selection sorting with input and output

Institution
Course

Content preview

Linear sort
1. Program to display the smallest number in an array using linear
search (ascending order)
#include<stdio.h>
int main() o/p

{ Enter the total Number of Elements : 5

int a[100], n, i, j, x;
printf("\nEnter the total Number of Elements : "); Enter the Array Elements : Enter 1 element67
Enter 2 element23
scanf("%d", &n);
Enter 3 element89
printf("\nEnter the Array Elements : ");
Enter 4 element32
Enter 5 element1
for(i=0;i<n;i++){
printf("Enter %d element", i+1);
Ascending order : 1 23 32 67 89
scanf("%d", &x); smallest number is:1
a[i] = x;
}


for(i = 0; i < n-1 ; i++)
{
for(j = i+1; j <n ; j++)
{
if(a[i]>a[j])
{
x = a[i];
a[i] = a[j];
a[j] = x;
}

, }
}
printf("\n Ascending order : ");
for(i = 0; i < n ; i++)
{


printf(" %d \t", a[i]);
}
printf("\n smallest number is:%d",a[0]);
return 0;
}

Bubble sort
2.Program to display largest number using bubble sort(ascending)


#include<stdio.h>

Enter the total Number of Elements : 4
int main()
{ Enter the Array Elements : Enter 1
element23
int a[100], n, i, j, x;
Enter 2 element86
printf("\nEnter the total Number of Elements : ");
Enter 3 element34
scanf("%d", &n);
Enter 4 element11
printf("\nEnter the Array Elements : ");

Ascending order : 11 23 34 86
for(i=0;i<n;i++){ largest number is:86
printf("Enter %d element", i+1);
scanf("%d", &x);

Written for

Course

Document information

Uploaded on
October 6, 2023
Number of pages
7
Written in
2023/2024
Type
Class notes
Professor(s)
M
Contains
Sorting and searching using c language

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
akheedhajan

Get to know the seller

Seller avatar
akheedhajan Kerala University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions