Write down the program to sort the array.

Answer Posted / rama krishna sidhartha

//code for ascending order
for(i=0;i<n-1;i++)
{
for(j=1+1;j<n;j++)
{
if(a[j] >a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

//code for descending order
for(i=n-1;i>0;i--)
{
for(j=n;j>i+1;j--)
{
if(a[j]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is more efficient, a switch statement or an if else chain?

585


How do you redirect a standard stream?

628


How can I implement sets or arrays of bits?

609


Explain what is a static function?

634


List the difference between a 'copy constructor' and a 'assignment operator' in C?

643






Give me the code of in-order recursive and non-recursive.

889


Describe the order of precedence with regards to operators in C.

635


Why do we need arrays in c?

589


Explain Basic concepts of C language?

649


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

645


How do you sort filenames in a directory?

716


What is #include cctype?

582


When should volatile modifier be used?

558


What is the best way to store flag values in a program?

583


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

693