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

struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

762


Explain what is the purpose of "extern" keyword in a function declaration?

613


What is new line escape sequence?

805


Can the sizeof operator be used to tell the size of an array passed to a function?

610


Is there sort function in c?

572






What are the rules for the identifier?

667


Explain what is meant by 'bit masking'?

638


how many errors in c explain deply

1625


Explain what is wrong in this statement?

632


What is the importance of c in your views?

586


What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

599


Can you please explain the difference between syntax vs logical error?

687


What is the use of parallelize in spark?

570


Can the curly brackets { } be used to enclose a single line of code?

709


What are the types of variables in c?

578