Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Write a program that takes in a set of numbers. The numbers will be stored in

ID: 3349136 • Letter: 3

Question

3. Write a program that takes in a set of numbers. The numbers will be stored in arn array. The size of the array (how many numbers to take in) is defined by the user. Then scan through the numbers in the array to do indexing from the smallest to the largest. You can choose to use any types of sorting methods An example of the output interface: Prepared by Name and ID: 12345 Class 3SPG1 This program takes in a set of numbers and performs sorting and indexing Please key how many numbers do you want to sort (max. 20): 5 Key in number #1 : 5 Key in number #2:4 Key in number #3-6 Key in number #4: 3 Key in number #5:1 The original order of the numbers are: 5 46 31 The sorted numbers are: 1 3 456 The index for number #1 (5) is 4 The index for number #2 (4) is 3 The index for number #3 (6) is 5 The index for number #4 (3) is 2

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

int main()

{

int a[30],b[30];

int ID,n,i,temp,j;

char s[10];

printf("prepared by name and ID:");

scanf("%d",&ID);

printf(" This program takes a set of numbers and performs sorting and indexing");

printf(" Please key how many numbers do you want to sort:");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf(" key in number # %d :",i+1);

scanf("%d",&a[i]);

}

printf(" the original order of numbers are:");

for(i=0;i<n;i++)

{

printf("%d",a[i]);

b[i]=a[i]; //copy into b

}

printf(" the sorted numbers are:");

for(i=0;i<n;i++) //sorting

{

for(j=i+1;j<n;j++)

{

if(a[j]>a[i])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

printf(" %d",a[i]);

}

for(i=0;i<n;i++)

{

printf(" the index for number #%d (%d) is %d ",i+1,b[i],a[i]);

}

getch();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote