ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2253)
 C++ interview questions  C++ Interview Questions (1111)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
Question
write a program to sort the elements in a given array in c
language
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
#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 ?    180 Yes 49 No
Rajesh Evani
 
Answer
# 2
#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 ?    141 Yes 110 No
Bhagya
 
 
 
Answer
# 3
#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 ?    17 Yes 11 No
Naga Tirupathi Rao
 
Answer
# 4
can i know how to write this program only using if else if
other than using for?
 
Is This Answer Correct ?    8 Yes 5 No
Puchu
 
Answer
# 5
#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 ?    4 Yes 1 No
Dibyendu
 
Answer
# 6
#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 ?    6 Yes 7 No
Rakesh Kumar
 
Answer
# 7
#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 ?    11 Yes 13 No
M. Ahsan
 
Answer
# 8
#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 7 No
Hguyiyo
 
Answer
# 9
#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 25 No
Balaji
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Write one statement equalent to the following two statements x=sqr(a); return(x); Choose from one of the alternatives a.return(sqr(a)); b.printf("sqr(a)"); c.return(a*a*a); d.printf("%d",sqr(a)); TCS 6
Why Modern OS are interrupt driven?Give an example   2
write function to reverse char array ... without using second array   2
x=2,y=6,z=6 x=y==z; printf(%d",x) HCL 13
What will be the result of the following program? main() { char p[]="String"; int x=0; if(p=="String") { printf("Pass 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } } a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation IBM 10
totally how much header files r in c language TCS 8
what is c   1
what is void pointer?   1
can we initialize all the members of union?   2
WAP to accept rollno,course name & marks of a student & display grade if total marks is above 200?   4
#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(%d\n, ++*I); Printf(%d\n, *++I); Printf(%d\n, (*I)--); Printf(%d\n, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300 Tieto 2
WRITE A PROGRAM IN C TO MULTIPLY TWO 2-D ARRAYS   4
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com