code for selection sort?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between functions getch() and getche().

826


What is a static variable in c?

883


Explain heap and queue.

828


Are there namespaces in c?

813


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

860


What is structure in c definition?

812


Write a progarm to find the length of string using switch case?

1867


Can you please explain the difference between exit() and _exit() function?

844


How many levels of indirection in pointers can you have in a single declaration?

860


Are there any problems with performing mathematical operations on different variable types?

828


What is time complexity c?

774


Why we use conio h in c?

918


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1683


Why ca not I do something like this?

813


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

1041