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 |
how to convert decimal to binary in c using while loop without using array
50 Answers Apple, Aptech, Arwen Tech, BCS, C2D Software, CEC,
Write down the difference between c. Loop and goto statement d. (!0) and (!1) e. (1= =! 1) and (1!=1) f. NULL and !NULL
How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis
Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.
I'm having trouble with coming up with the correct code. Thank You!! The assignment was to write a program using string functions that accepts a price of an item and displays its coded value. The base of the keys: X C O M P U T E R S 0 1 2 3 4 5 6 7 8 9 Sample I/O Dialogue: Enter Price: 489.50 Coded Value: PRS.UX
quoroum of computer languages?
what is exceptions?
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .
void main() { for(int i=0;i<5;i++); printf("%d",i); } What is the output?..
32 Answers College School Exams Tests, CTS, HCL, iGate, SmartData,
2. A student studying Information Technology at Polytechnic of Namibia is examined by coursework and written examination. Both components of assessment carry a maximum of 50 marks. The following rules are used by examiners in order to pass or fail students. a. A student must score a total of 40% or more in order to pass (total = coursework marks + examination marks) b. A total mark of 39% is moderated to 40% c. Each component must be passed with a minimum mark of 20/50. If a student scores a total of 40% or more but does not achieve the minimum mark in either component he/she is given a technical fail of 39% (this mark is not moderated to 40%) d. Grades are awarded on marks that fall into the following categories. Mark 100-70 69-60 59-50 49-40 39-0 Grade A B C D E Write a program to input the marks for both components (coursework marks out of 50 and examination marks out of 50), out put the final mark and grade after any moderation. [30]
Why are memory errors hard to debug?
Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;