write a program to arrange the contents of a 1D array in
ascending order
Answer Posted / kameshav
int main()
{
int a[20],n,i,j,temp;
printf("Enter the size of an array : ");
scanf("%d",&n);
printf("Enter the array elements : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nAscending Order\n");
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
printf("%d\n",a[i]);
}
return 0;
}
| Is This Answer Correct ? | 23 Yes | 19 No |
Post New Answer View All Answers
What is the difference between abs() and fabs() functions?
Why static variable is used in c?
Why header file is used in c?
What is the value of h?
Does sprintf put null character?
Can two or more operators such as and be combined in a single line of program code?
Explain #pragma statements.
formula to convert 2500mmh2o into m3/hr
Why does the call char scanf work?
Is array a primitive data type in c?
What are the types of unary operators?
What is break in c?
What will be your course of action for a push operation?
Tell me the use of bit field in c language?
What is the difference between declaring a variable by constant keyword and #define ing that variable?