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

Calculate 1*2*3*____*n using recursive function??

1759


What is structure in c language?

834


write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)

1889


What is NULL pointer?

863


What is formal argument?

891


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

863


What is the difference between void main and main in c?

876


What is the difference between union and anonymous union?

1050


What is the purpose of sprintf() function?

819


What is the process to create increment and decrement stamen in c?

801


Write a program on swapping (100, 50)

868


Explain the term printf() and scanf() used in c language?

829


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

1924


Explain what’s a signal? Explain what do I use signals for?

797


Can you please explain the scope of static variables?

806