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

Answers were Sorted based on User's Feedback



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

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

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

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

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

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

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

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

Post New Answer

More C Interview Questions

Why is c known as a mother language?

0 Answers  


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?

0 Answers  


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?

2 Answers   Zensar,






Print the foll in C...eg when n=5 the o/p must b + + + + + + + + + + + + + + + + +

1 Answers  


Write a C program to print 1 2 3 ... 100 without using loops?

15 Answers   Hindalco,


What is a double c?

0 Answers  


say the following declaration is correct nr not. int b=a,n=0;

4 Answers   Wipro,


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

0 Answers  


What is a string?

0 Answers  


what is the different between data structure and data type?

1 Answers   Ignou,


Categories