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


Please Help Members By Posting Answers For Below Questions

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)

1635


What's the total generic pointer type?

620


Is malloc memset faster than calloc?

622


Should a function contain a return statement if it does not return a value?

601


what is a function method?give example?

1918






What are examples of structures?

601


How do you redirect a standard stream?

628


Hai what is the different types of versions and their differences

1495


I heard that you have to include stdio.h before calling printf. Why?

592


What is #include stdio h and #include conio h?

605


What is console in c language?

616


how to build a exercise findig min number of e heap with list imlemented?

1614


What happens if header file is included twice?

660


code for quick sort?

1626


largest Of three Number using without if condition?

1012