jituTechnology

jituTechnology

Write a program to sort the data in ascending and descending order using bubble sort.

/*program to sort the data in ascending order using bubble sort.
Programmed by :Jitendra Kumar Yadav
roll ni.: 10116
programmed on.: 21st mar,2011*/
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,temp;
int arr[10]={2,1,6,5,8,4,9,7,10,3};
for (i=0;i<10;i++)
{
for (j=0;j<10-i;j++)
if(arr[j]>arr[j+1])// if you want for descending order then changeif(arr[j]>arr[j+1] to if(arr[j]<arr[j+1]
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
for (i=0;i<10;i++)
printf (“\n%d”,arr[i]);
getch();
}

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

May 2024
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031