write a program to arrange the contents of a 1D array in
ascending order

Answer Posted / rajeev

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,temp;
clrscr();
printf("\n enter the size of the array");
scanf("%d",&n);
printf("\n enter the contents of the array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<(n-1)-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
getch();
}

Is This Answer Correct ?    10 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is modeling?

824


What is pointers in c?

897


What are the parts of c program?

855


How can I manipulate individual bits?

809


Is null always defined as 0(zero)?

824


How can a program be made to print the line number where an error occurs?

878


List a few unconditional control statement in c.

774


When can a far pointer be used?

774


What does %p mean c?

829


Write a program to reverse a string.

847


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

917


What are the loops in c?

779


Write a program to find factorial of a number using recursive function.

861


What is the use of typedef in c?

794


Can main () be called recursively?

887