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 |
loop1: { x=i<n?(i++):0; printf("%d",i); exit(x); continue; } Error- misplaced continue. Doubt-1.will the exit(x) be executed for all values of x 2.will this statement go out of the program.
How to create a program that lists countries capitals when country is entered? (Terribly sorry, I'm a complete novist to coding with C, am looking for inspiration and general tips on how to code and create this program.)
void main() { int i=7; printf("N= %*d",i,i); }
write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;
Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;
Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10
Why are memory errors hard to debug?
Using string functions write a program that will accept the name of the capital as input value and will display the corresponding country. ------------------------ Capitals Countries ------------------------ Capitals Countries Ottawa Canada Moscow Russia Rome Italy I can't not get it to run properly
#include"stdio.h" #include"conio.h" void main() { int a; printf("\n enter a number:"); scanf("%c\n"); getch(); }
what is macro in c? Difference between single linked list & double linked list what is fifo & lifo? what is stack & queue?
full c programming error question based problem
#include<>stdio.h> #include<>conio.h> { printf("hello"); void main() getch(); } what the out put of this program and why ......plz clear my answer