This program should compile on visual studio\'s 2010 and written in C. I will li
ID: 3624761 • Letter: T
Question
This program should compile on visual studio's 2010 and written in C. I will list the requirments and give an example that may help. Thank you...
Use any sorting routine that you like. Write your program so that the user gets to enter 10 numbers from the keyboard to be sorted. The output from your program should be 2 columns of numbers. The left column should be the numbers in the order they were originally entered and the right column should be the sorted list. The columns should be labeled. You will need 2 arrays to accomplish this.
Use separate functions for input, sorting, and printing.
This is exercise 9 program that exercise 10 is refers to.
Explanation / Answer
please rate - thanks
#include <stdio.h>
void insertion(int [],int);
void getarray(int[],int[],int);
int fm(int[],int,int,int*);
void printdata(int[],int[],int);
int main()
{int i,numbers[10],saved[10],n=10;
getarray(numbers,saved,n);
insertion(numbers,n);
printdata(numbers,saved,n);
return 0;
}
void printdata(int a[],int b[],int n)
{int i;
printf("before after sort sort ");
for(i=0;i<n;i++)
printf("%d %d ",b[i],a[i]);
printf(" ");
}
void getarray(int a[],int b[],int n)
{int i;
printf("Enter 10 numbers: ");
for(i=0;i<n;i++)
{printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
b[i]=a[i];
}
}
void insertion(int num[],int n)
{ int i,j,c,m,key,t;
for(i=0;i<n-1;i++)
{key=fm(num,i,n,&c);
t=num[key];
num[key]=num[i];
num[i]=t;
m++;
}
}
int fm(int num[],int b,int n,int* comp)
{
int f = b;
int c;
for(c = b + 1; c < n; c++)
{*comp=*comp+1;
if(num[c] < num[f])
f = c;
}
return f;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.