Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C programing. Instead of write a code like below, i have to use pointer to access the array and pass the value -Problem 3:

Using C programing.

Instead of write a code like below, i have to use pointer to access the array and pass the value

-Problem 3:

#include

void displayArray(unsigned int a[], int asize, int fieldWidth, int showPerLine)

{

puts(" Array Values ");

for(int i = 0; i

{

if( (i % showPerLine) == 0)

puts("");

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

}

puts(" "); // 2 blank lines

}

int main(void)

{

const int alength = 20;

unsigned int arr[alength];

for(int i = 0; i

arr[i] = i;

displayArray(arr, alength, 8, 6);

return 0;

}

-Problem 4:

#include

#include

void fillArray(int a[], int asize, int lowValue, int highValue)

{

for(int i = 0; i

a[i] = rand()%(highValue-lowValue+1) + lowValue;

}

void displayArray(int a[], int asize, int fieldWidth, int numPerLine)

{

for(int i = 0; i

{

if( (i % numPerLine) == 0)

puts("");

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

}

puts(""); // blank line

}

/** Sort array elements into ascending order */

void bubbleSort(int a[], int asize)

{

for(int outer = 0; outer

{

for(int inner = 0; inner

{

if(a[outer]

{

int temp = a[outer];

a[outer] = a[inner];

a[inner] = temp;

}

}

}

}

int main(void)

{

const int arraySize = 30;

const int fieldWidth = 5;

const int printPerLine = 6;

const int lowRandom = -100;

const int highRandom = 100;

int arr[arraySize];

srand(0);

fillArray(arr, arraySize, lowRandom, highRandom);

puts(" Unsorted Array ");

displayArray(arr, arraySize, fieldWidth, printPerLine);

bubbleSort(arr, arraySize);

puts(" Sorted Array ");

displayArray(arr, arraySize, fieldWidth, printPerLine);

return 0;

}

image text in transcribed

Rewrite the program, hwpointers_03.c, using only pointer notation to access array elements and to define arrays as parameters. No credit will be awarded for using subscript [ notation. The [ notation is allowed (and necessary) to create the array. (10 points) 3. Example unsigned int array[20]; arraylivalue //brackets allowed to declare array // not ok, use pointers to access array elements ubbleSort, fillArray, and Rewrite the program, hwpointers 04.c so that the b displayArray functions use only pointers. No credit will be awarded for using subscript notation to access the array. (15 points) 4. A bubble sort is the simplest method of sorting arrays. Each array element is compared with every other array element in an organized sequence. When one value is larger (or smaller) than another, the values are swapped. The comparison continues, checking each permutation of comparisons in the array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Define the term Working Capital Gap.

Answered: 1 week ago