Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

C Programming only. (NO C++) Copy & paste all source code with your answer. Also take screenshot of it compiled. //---------------------------------------------------- // Assignment #5, Problem

C Programming only. (NO C++)

Copy & paste all source code with your answer.

Also take screenshot of it compiled.

image text in transcribed

//----------------------------------------------------

// Assignment #5, Problem #13

// Problem13.c

//----------------------------------------------------

#include

#include

#include

#include "..\..\Random.h"

//----------------------------------------------------

int main()

//----------------------------------------------------

{

void BuildXs(int n,int LB,int UB,int *xs);

void DisplayXs(int n,int xs[]);

int n;

SetRandomSeed();

printf("n? ");

while ( scanf("%d",&n) != EOF )

{

int LB,UB;

int *xs = (int *) malloc(sizeof(int)*(n+1));

printf("LB? "); scanf("%d",&LB);

printf("UB? "); scanf("%d",&UB);

BuildXs(n,LB,UB,xs);

DisplayXs(n,xs);

// What statement belongs here to ensure that you maintain your reputation

// as "a good heap-citizen"?

printf(" n? ");

}

system("PAUSE");

return( 0 );

}

//----------------------------------------------------

void BuildXs(int n,int LB,int UB,int *xs)

//----------------------------------------------------

{

int i;

Student provides missing code to store a randomly-chosen integer from [ LB,UB ]

into xs[i], i in [ 1,n ]. Hint Use RandomInteger().

}

//----------------------------------------------------

void DisplayXs(int n,int xs[])

//----------------------------------------------------

{

/*

1 2 3 4 5 6

12345678901234567890123456789012345678901234567890123456789012345678

1- 10: XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX

11- 20: XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX

. . . . . . . . . . . .

XXX-XXX: XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX

*/

int i;

for (i = 1; i

{

Student provides missing code to output each element xs[i], i in [ 1,n ],

according to the format requirements shown in the comment above.

Hint There are edge-cases associated with the beginning and

ending of every line of output!

}

printf(" ");

}

14. Problen13.c creates the n-element vector xs U , fills it with integers randomly-chosen from LB, UB 1, then displays it. Add the function BubbleSortXsInAscendingOrder0 to the Problem13.c software architecture (see below) and "tweak" main) by adding calls to BubbleSortXsInAscendingOrder) and to DisplayXs) in the right places. This problem requires that you sort xs[] then display it again to "prove" that your sort works void BubbleSortxsInAscendingOrder (int n,int xsI1 Bubble Sort (ascending-order pass 1 DO swapMadefalse FOR i : 1 TO (n-pass) BY1 swap xs[il and xs[i+1l swadMadetrue END END passpasst1 WHILE swapMade ) Sample Program Dialo EACOURSESCS1311Code REVIEWAssignment5 Problem14.exe ? 35 B? 1 B? 100 82 53 63 59 1-18 11-20 21- 30 31- 40 72 87 21 16 92 29 23 80 91 26 578752 58 77 74 43 36 83 26 60 6773 16 81 95 94 1- 10: 11- 20: 21- 30: 31-40 26 59 82 29 60 83 36 63 87 21 21 26 43 67 87 52 72 91 57 94 94 81 92

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions