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 |
errors are known as?
3 Answers EX, State Bank Of India SBI,
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).
Write a C program to enter 10 integer numbers through one variable and count how many of them are even using while loop ?
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.
what is run time error?
Why are memory errors hard to debug?
I'm having trouble with coming up with the correct code. Do I need to put a loop? Please let me know if I'm on the right track and what areas I need to correct. I still don't have a good grasp on this programming stuff. Thanks =) The assignment was to write a program using string functions that accepts a coded value of an item and displays its equivalent tag price. The base of the keys: 0 1 2 3 4 5 6 7 8 9 X C O M P U T E R S Sample I/O Dialogue: Enter coded value: TR.XX Tag Price : 68.00
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.)
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 .
which typw of errors ? & how to solve it ?
write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;
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]