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
What is modeling?
What is pointers in c?
What are the parts of c program?
How can I manipulate individual bits?
Is null always defined as 0(zero)?
How can a program be made to print the line number where an error occurs?
List a few unconditional control statement in c.
When can a far pointer be used?
What does %p mean c?
Write a program to reverse a string.
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)
What are the loops in c?
Write a program to find factorial of a number using recursive function.
What is the use of typedef in c?
Can main () be called recursively?