#include(conio.h)
void main( )
{
int a[10], n, i, j, temp;
clrscr( );
cout<<"Enter the no. of elements:";
cin>> n;
cout<<"Enter the array elements:";
for(i=0; i< n; i++)
cin>>a[i];
//------Operation part-------
for( i=0; i< n; i++)
{
for(j=i; j< n-1; j++)
{
if(a[i]> a[j+1] )
{
temp= a[i];
a[i]= a[j+1];
a[j+1]= temp;
}
}
}
cout<<"Elements after sorting:";
for( i=0; i< n; i++)
cin>> a[i];
}
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
its very useful for computer students thanks for your good job
ReplyDeletethank u it was very helpfull
ReplyDeletethanks alot, i still need to know functions you used like conio.h getch and clrscr
ReplyDeleteconio.h is the header file where we have the functions like getch and clrscr.
Deleteclrscr- is a function that is used to clear the screen after u come out of the program after seeing the output so next time wen u run the program u dont see previous output.
getch - helps in displaying the output on the screen
.
Hi there,
ReplyDeleteFor displaying the numbers in descending order is it ok if we change the last part of displaying in the program as below:
for(i=n;i<0;i--)
{
cout<<a[i]
}
no just change this condition if(a[i]> a[j+1] ) to if(a[i]< a[j+1] ) this..!! u will get all the numbers in descending order..!!
DeleteThanks! :)
ReplyDeletegive the code for arrange the given marks in ascending order using file operations in c++
ReplyDeletevery nice !!!!!
ReplyDeletethanks brooo.
ReplyDeleteavoid clrscr() and
change cin>> to cout<< in the last line.......errors!!!
is the prograM exceuing/ WORKING
ReplyDeleteExecuted successfully............!!!!
ReplyDeleteBUGOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ReplyDeleteMALI MAN UI!!!
BUGO NA PROGRAMMER!!!!!!!!!!!!!!!!!
its simple n easy to undrstnd for beginers.. thank you
ReplyDeleteits simple n easy to undrstnd for beginers.. thank you
ReplyDeletedo you know how to program ascending in java way..
ReplyDeleteC++ program to Sort an Array Elements
ReplyDeletegreat post
Hey dude great programme...
ReplyDeleteBut just one question...
In the last for lop I guess it should be cout>>a[i]...
Just check it out...
This comment has been removed by the author.
ReplyDeleteWhy is it compulsory to have an array whose length is constant.
ReplyDeleteWhy to restrict the user to enter only 10 values. Can't there be run time initialization in array???
int n;
cin>>n;
int arr[n];
for(int i =0;i>n;i++)
cin>>arr[i];
Why this code isn't acceptable. What is the solution for such problem. kindly reply.
why is void main() used here?\
ReplyDeletecan we write
ReplyDeletevoid main()
int main ()
both toghether
what is the meaning of int a[10]
ReplyDeleteint a[10],temp;
ReplyDeletei could not understand this what doe this mean
i would be very thankfull if someone clears my doubts
cout<<"enter the array elements:";
ReplyDeletewhat does this means and what are arrays?
what is meant by i++
ReplyDeleteand can anyone explain me the logic please request
my email id dhankhar7924@gmail.com
thank you friend.........
ReplyDeleteWhat is the output
ReplyDeleteThis code is very simple and easy to learn.
ReplyDeleteSort an Array Elements in Ascending Order in C++