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

Write a program to print all the prime numbers with in the given range

8 Answers   ABC, College School Exams Tests, TCS,


Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage

7 Answers   Accenture,


Where does the name "C" come from, anyway?

0 Answers   Celstream,


Do pointers take up memory?

0 Answers  


What is the use of in c?

0 Answers  






Explain the priority queues?

0 Answers  


program to print circle structure

1 Answers  


Differentiate between the expression “++a” and “a++”?

0 Answers  


What are the different types of control structures in programming?

0 Answers  


What is local and global variable in c?

0 Answers  


What are two dimensional arrays alternatively called as?

0 Answers  


What is c variable?

0 Answers  


Categories