code for selection sort?



code for selection sort?..

Answer / naveen shukla

#include<stdio.h>
#include<stdlib.h>
int main(){
int n,i,t;
printf("Enter the size of the array");
scanf("%d",&n);
int *p=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++){
printf("Enter the %d" i+1 "number in the array");
scanf("%d;t);
*(p+i)=t;
}
for(j=0;j<n-1;j++){
int pos=j;
int k=j+1;
int min=*(p+j);
while(k<n){
if(a[k]<min){
m=p[k];
pos=k;
}
k++;
}
int temp=p[pos];
p[pos]=a[j];
a[j]=temp;
}
return 0;
}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Interview Questions

What does the error message "DGROUP exceeds 64K" mean?

0 Answers   Celstream,


What are runtime error?

0 Answers  


Write a simple program to find the size of different basic data types in C.

3 Answers  


Can we assign integer value to char in c?

0 Answers  


how to use showbits function?

2 Answers   Infosys, TATA,






what is pointer?

4 Answers  


Explain how can you tell whether a program was compiled using c versus c++?

0 Answers  


Write a code on reverse string and its complexity.

0 Answers   Expedia,


Why is c called c?

0 Answers  


why wipro wase

0 Answers   Wipro,


What is a double c?

0 Answers  


palindrome for strings and numbers----Can anybody do the prog?

6 Answers   CTS, TCS, Vipro Lifescience Pvt,


Categories