Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Done in C please Pointers: Write a function swap that takes as arguments two pointers to integers. This function should swap the values pointed to

//Done in C please

Pointers:

Write a function swap that takes as arguments two pointers to integers. This function should swap the values pointed to by the pointers passed to the function. So, if there were two pointers, a and b , which point to integers 5 and 7, respectively, then after the function should run, then a should point to an integer with value 7 and b should point to an integer with a value of 5. Write a program that prompts a user to enter 15 integers. The program should store those integers in an array. Then use the function you wrote to swap the 0th element with the 7th, the 8th with the 3rd, and the 14th with the 0th (in that order). The program should then print the values stored by the array after the swaps.

The output of the program should look like this:

Enter 15 integers:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Swapped array:

14 1 2 8 4 5 6 0 3 9 10 11 12 13 7

Algorithm Design Process:

1. Lets write the function first:

a. What should the function prototype look like?

b. What variables are needed inside the function?

c. How can we test the function with a simple program?

d. How does swap work? How can we swap the values of two variables without overwriting

one or the other?

2. OK, now for the program:

a. We need to store variables in an array, how should the array be declared?

b. The function swap needs pointers to the variables that are going to be switched. how can

we get pointers to specific elements of an array

image text in transcribed

image text in transcribed

Pointers Write a function swap that takes as arguments two pointers to integers. This function should swap the values pointed to by the pointers passed to the function. So, if there were two pointers, a and b, which point to integers 5 and 7, respectively, then after the function should run, then a should point to an integer with value 7 and b should point to an integer with a value of 5. Write a program that prompts a user to enter 15 integers. The program should store those integers in an array. Then use the function you wrote to swap the 0th element with the 7th, the 8th with the 3rd, and the 14th with the 0th (in that order). The program should then print the values stored by the array after the swaps. The output of the program should look like this: Enter 15 integers: 01 23 45 67 8 9 10 11 12 13 14 Swapped array: 14 1 2 8 45 60 3 910 11 12 13 7

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_2

Step: 3

blur-text-image_3

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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions