/*------------------------------------------------------------------------------------------------
Program : Write a program in C to Sort N Integer
Using Bubble Sort.
Created
By: JABIR DAUD PATHAN
Branch : COMPUTER ENGINEERING
-------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<conio.h>
void
main()
{
int arr[100],i,j,temp,n;
clrscr();
printf("Enter the How many Elements you
want to enter in array==>");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("\nEnter elements for
arr[%d]=",i);
scanf("%d",&arr[i]);
}
printf("\n\nAccepted Array Elements
Are==>\n ");
for(i=0;i<=n-1;i++)
{
printf("\n arr[%d]=%d",i,arr[i]);
}
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(arr[j]>arr[i])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\n\n\nThe content of an array in
an ascending order are==>\n");
for(i=0;i<=n-1;i++)
{
printf("\narr[%d]=%d",i,arr[i]);
}
getch();//To get quick output window
}
/*-----------------<< OUTPUT SCREEN >>-------------------*/
Enter
the How many Elements you want to enter in array==>9
Enter
elements for arr[0]=9
Enter
elements for arr[1]=1
Enter
elements for arr[2]=8
Enter
elements for arr[3]=2
Enter
elements for arr[4]=7
Enter
elements for arr[5]=3
Enter
elements for arr[6]=6
Enter
elements for arr[7]=4
Enter
elements for arr[8]=5
Accepted Array Elements Are==>
arr[0]=9
arr[1]=1
arr[2]=8
arr[3]=2
arr[4]=7
arr[5]=3
arr[6]=6
arr[7]=4
arr[8]=5
The content of an array in an ascending order
are==>
arr[0]=1
arr[1]=2
arr[2]=3
arr[3]=4
arr[4]=5
arr[5]=6
arr[6]=7
arr[7]=8
arr[8]=9
No comments:
Post a Comment