write a profram for selection sort
whats the error in it?
Answers were Sorted based on User's Feedback
Answer / joshin
//program for selection sort
#include<stdio.h>
#include<conio.h>
#define MX 100
void selection(int [], int);
void selection(int a[],int n)
{
int minindx,t;
int i,j;
for(i=0;i<n-1;i++)
{
minindx=i;
for(j=i+1;i<n;j++)
{
if(a[j]<a[minindx])
minindx=j;
}
if(minindx!=i)
{
t=a[i];
a[i]=a[minindx];
a[minindx]=t;
}
}
}
void main()
{
int a[MX],i,n;
clrscr();
printf("enter total num of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
selection(a,n);
printf("sorted arrau:\n");
for(i=0;i<n;i++)
{
printf("%d \t",a[i]);
}
getch();
}
Is This Answer Correct ? | 8 Yes | 1 No |
#include<iostream>
using namespace std;
int main()
{
int i,t,j,min,n=0,m=0;
int a[6]={6,3,2,10,5,8};
//0 1 2 3 4 5
for(i=0;i<=13;i++)
{
m++;
min=i;
for(j=i+1;j<=5;j++)
{
if(a[j]<a[min])
min=j;
n++;
}
t=a[i];
a[i]=a[min];
a[min]=t;
}
cout<<"******Selection Sort*********"<<endl;
for(i=0;i<=5;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
cout<<"Outer Loop Total count :"<<m<<endl;
cout<<"Inner Loop Total count :"<<n<<endl;
return 0;
}
Is This Answer Correct ? | 1 Yes | 0 No |
full c programming error question based problem
Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.
how tally is useful?
what is meant for variable not found?
What is probability to guarantee that the task a programmer is going to create will be created and be able to run on a particular system (RTOS/GPOS).
void main() { int i=7; printf("N= %*d",i,i); }
Declaration of Cube Guys please help me.. Is this a right way to declare cube.? If i Compile it. It Says: Cube undeclared what should i do? Please help \thanks in advanced #include<stdio.h> #include<math.h> #include<conio.h> main( ) { float x,y; while(x++<10.0) { printf("Enter Number:"); scanf("%d", &x); y = cube(x); printf("%f %f %f \n", x,pow(x,2),y); cube(x); } { float x; float y; y = x*x*x; } getch(); return (y); }
how to convert decimal to binary in c using while loop without using array
50 Answers Apple, Aptech, Arwen Tech, BCS, C2D Software, CEC,
what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?
#include"stdio.h" #include"conio.h" void main() { int a; printf("\n enter a number:"); scanf("%c\n"); getch(); }
Why are memory errors hard to debug?
What is the code for following o/p * * * * * * * * * * * * * * * *