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 convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

0 Answers   Subex,


What is c token?

0 Answers  


Given a number N, product(N) is the product of the digits of N. We can then form a sequence N, product(N), product(product(N))… For example, using 99, we get the sequence 99, 99 = 81, 81 = 8. Input Format: A single integer N Output Format: A single integer which is the number of steps after which a single digit number occurs in the sequence. Sample Test Cases: Input #00: 99 Output #00: 2 Explanation: Step - 1 : 9 * 9 = 81 Step - 2 : 8 * 1 = 8 There are 2 steps to get to this single digit number. Input #01: 1137638147

2 Answers  


what is a function prototype?

1 Answers  


i have a written test in tomorrow

1 Answers   NNN, Value Labs,






Write a programe print the sum of series 0,1,2,.....10

7 Answers  


Explain what is meant by 'bit masking'?

0 Answers  


Write a C Programm.. we press 'a' , it shows the albhabetical number is 1, if we press 'g' it shows the answer 7.. any can help me

7 Answers  


will u please send me the placement papers to my mail???????????????????

0 Answers  


Why can’t constant values be used to define an array’s initial size?

0 Answers  


What is const keyword in c?

0 Answers  


What does volatile do?

0 Answers  


Categories