write a program to sort the elements in a given array in c
language
Answers were Sorted based on User's Feedback
Answer / rajesh evani
#include<stdio.h>
void main()
{
int a[5],t;
int i,j=0;
printf("enter 5 values into the array a");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("the sorted order of elements");
for(i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i<5;i++)
{
printf("%d",a[i]);
}
}
| Is This Answer Correct ? | 225 Yes | 62 No |
Answer / bhagya
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5];
int i,j=0;
printf("enter 5 values into the array a");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("the sorted order of elements");
for(i=0;i<5;i++)
{ t=a[i];
for(j=0;j<5;j++)
{
if(a[i]>a[j])
a[i]=a[j];
a[j]=t;
}
}
}
| Is This Answer Correct ? | 144 Yes | 123 No |
#include<stdio.h>
#include<conio.h>
main()
{
int a[25],i,n,sum=0;
clrscr();
prinf("enter the size of array");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("element%d=",i);
scanf("%d",&a[i]);
sum=sum+a[i];
}
printf("ascending orderis:");
for(j=0;j<=sum;j++)
{
for(i=1;i<=n;i++)
{
if(j==a[i])
printf("%d",j);
}
}
getch();
}
| Is This Answer Correct ? | 22 Yes | 15 No |
Answer / puchu
can i know how to write this program only using if else if
other than using for?
| Is This Answer Correct ? | 13 Yes | 6 No |
Answer / 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 |
Answer / yoyo
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5];
int i,j=0;
printf("enter 5 values into the array a");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("the sorted order of elements");
for(i=0;i<5;i++)
{ t=a[i];
for(j=0;j<5;j++)
{
if(a[i]>a[j])
a[i]=t;
a[i]=a[j];
a[j]=t;
}
}
}
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / m. ahsan
#include <stdio.h>
#include <conio.h>
//Sorting an array with a single FOR loop. No complex coding and testing with multiple array sizes.
int main()
{ clrscr();
int xlist[5]={5,3,4,1,2};
int i,temp;
for (i=0;i<4;)
{
if (xlist[i]<xlist[i+1])
i++;
else
{ temp=xlist[i];
xlist[i]=xlist[i+1];
xlist[i+1]=temp;
i=0;
}
}
for (i=0;i<5;i++)
{ printf("%d ",xlist[i]); }
getch();
return 0;
}
| Is This Answer Correct ? | 14 Yes | 15 No |
Answer / rakesh kumar
#include<stdio.h>
#include<conio.h>
#define MAX 10
void main()
{
int list[MAX],i,j,temp;
printf("input a 10 numbers");
for(i=0;i<MAX;i++)
{
scanf("%d",&list[i]);
}
for(i=0;i<MAX;i++)
{
for(j=i+1;j<MAX-1;j++)
{
if(list[i]>list[j])
temp=list[j];
list[j]=list[i];
list[j]=temp;
}
}
printf("Sort the number assending order");
for(i=0;i<MAX;i++)
{
printf("%d",list[i]);
}
getch();
}
| Is This Answer Correct ? | 8 Yes | 9 No |
Answer / hguyiyo
#include<stdio.h>
main()
{
int i, count=0;
int n,num,t;
scanf("%d",&n);
int a[n];
while(count!=n)
{
scanf("%d",&num);
a[count]=num;
++count;
}
for(i=0;i<n;++i) printf(" %d ",a[i]);
printf("\n\n\n\n");
for(i=0;i<n;++i)
if(a[i]<=a[i+1]) ;
else
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
for(i=0;i<n;++i) printf(" %d ",a[i]);
}
| Is This Answer Correct ? | 4 Yes | 8 No |
Answer / balaji
#include<stdio.h>
#include<conio.h>
main()
{
int temp,i,j,n=10;
int arr[n];
clrscr();
printf("\n\tEnter The Values into array");
for(i=0;i<n;i++){
printf("\n Enter Element no %d: ",i);
scanf("%d",&arr[i]);}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(arr[j] > arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j]=temp;}
}}
printf("\n-- Sorted Series --");
for(i=0;i<n;i++){
printf("\t %d",arr[i]);}
getch();
}
| Is This Answer Correct ? | 16 Yes | 27 No |
What are the storage classes in C?
write a program to remove duplicate from an ordered char array? in c
Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent
What is clrscr in c?
int main() { int x = (2,3,4); int y = 9,10,11; printf("%d %d",x,y); } what would be the output?
What does volatile do?
What is the difference between the expression “++a” and “a++”?
What is the purpose of scanf() and printf() functions?
Was 2000 a leap year?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
write a c program to change only the 3rd bit of the particular number such that other bits are not affected.. if bitnum=10(say.. it can be any no..
though sbi was nationalized why its not comes under nationalized banks and its comes under publicsector banks
3 Answers State Bank Of India SBI,