write a program to arrange the contents of a 1D array in
ascending order
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / kameshav
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]);
}
printf("\nAscending Order\n");
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("%d\n",a[i]);
}
return 0;
}
Is This Answer Correct ? | 23 Yes | 19 No |
Answer / 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 |
Answer / prakashmca
#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-1;i++)
{
for(j=0;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
getch();
}
Is This Answer Correct ? | 7 Yes | 14 No |
Why is c known as a mother language?
what will be the output: main(){char ch;int a=10;printf("%d",ch);}
36 Answers Accenture, TCS, Wipro,
Is c is a low level language?
what is pointer?
13 Answers HCL, TCS,
write a function that accepts an array A with n elements and array B with n-1 elements. Find the missing one in array B,with an optimized manner?
Print the foll in C...eg when n=5 the o/p must b + + + + + + + + + + + + + + + + +
Write a C program to print 1 2 3 ... 100 without using loops?
What is a double c?
say the following declaration is correct nr not. int b=a,n=0;
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
What is a string?
what is the different between data structure and data type?