write a program to arrange the contents of a 1D array in
ascending order
Answer Posted / poornima
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]);
}
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("\nAscending Order\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
Is This Answer Correct ? | 65 Yes | 22 No |
Post New Answer View All Answers
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
What's the total generic pointer type?
Is malloc memset faster than calloc?
Should a function contain a return statement if it does not return a value?
what is a function method?give example?
What are examples of structures?
How do you redirect a standard stream?
Hai what is the different types of versions and their differences
I heard that you have to include stdio.h before calling printf. Why?
What is #include stdio h and #include conio h?
What is console in c language?
how to build a exercise findig min number of e heap with list imlemented?
What happens if header file is included twice?
code for quick sort?
largest Of three Number using without if condition?