Write down the program to sort the array.
Answers were Sorted based on User's Feedback
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(arr[j] >a[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
| Is This Answer Correct ? | 15 Yes | 4 No |
Answer / 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 |
Answer / anon
#include <stdio.h>
int main() {
int i, j, size, values[100], temp;
printf("Enter the size of an array: ");
scanf("%d",&size);
printf("Enter the values of array: ");
for(i=0;i<size;i++){
scanf("%d",&values[i]);
}
for(i=0;i<size-1;i++){
for(j=i+1;j<size;j++){
if(values[i]<values[j]){
temp=values[i];
values[i]=values[j];
values[j]=temp;
}
}
}
printf("Sorted array:
");
for(i=0;i<size;i++){
printf("%d ",values[i]);
}
return 0;
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Why can’t constant values be used to define an array’s initial size?
In which mode we open the file for read,write and append also in c ? a)W b)w+ c)r+ d)a
What is external and internal variables What is dynamic memory allocation what is storage classes in C
What is the purpose of #pragma directives in C?
what is the difference between const volatile int i & volatile const int j;
How can I recover the file name given an open stream?
Why is event driven programming or procedural programming, better within specific scenario?
what is the use of getch() function in C program.. difference b/w getch() and getche()??
29 Answers HCL, IBM, Infosys, TCS, Wipro,
What are pointers really good for, anyway?
A stack can be implemented only using array?if not what is used?
What is local and global variable in c?
what is the difference between <stdio.h> and "stdio.h"
14 Answers Invendis, Kanbay, Mastek, MathWorks,