write a program to sort the elements in a given array in c
language
Answer Posted / dibyendu
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[100],j,n,i,tmp;
printf(" Enter the size of the array \t");
scanf("%d",&n);
printf("Now enter the elements in the array \n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]>ar[j+1])
{
tmp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=tmp;
}
}
}
printf("\n\n Array in the ascending order is - \n");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
getch();
}
| Is This Answer Correct ? | 7 Yes | 3 No |
Post New Answer View All Answers
What is 02d in c?
What does %c do in c?
What is the use of c language in real life?
What is cohesion in c?
Explain is it valid to address one element beyond the end of an array?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
How can a number be converted to a string?
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
write a c program for swapping two strings using pointer
Is c language still used?
Which is better between malloc and calloc?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
What is the use of putchar function?
How do c compilers work?