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

write a program to display reverse of a number using for loop?

14 Answers  


What is the use of header files?

0 Answers  


Diff between for loop and while loop?

2 Answers   TCS,


Which programming language is best for getting job 2020?

0 Answers  


10. Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning

5 Answers   Accenture,






pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

0 Answers   Huawei,


what is data structure?

5 Answers   CBSE,


what is the difference between #include<stdio.h> and #include "stdio.h" ?

3 Answers  


What is an auto variable in c?

0 Answers  


What does void main () mean?

0 Answers  


what is pointer

1 Answers   TCS,


Explain what is the stack?

0 Answers  


Categories