Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the code to left rotate four integers by one position. Function rotate_4() takes four integer pointers as parameters and returns nothing. This is a

complete the code to left rotate four integers by one position. Function rotate_4() takes four integer pointers as parameters and returns nothing. This is a classic example of how pass-by-reference is more efficient in updating a batch of variables. Think about it: if you are not allowed to use pointers, how can you implement it?

Some example outputs follow:

% ./rotate 1 2 3 4

2 3 4 1

% ./rotate 1 2 3

Error: rotate needs four numbers

#include #include

void rotate_4(int *p_a, int*p_b, int*p_c, int* p_d) { //TO-DO: please implement left rotate 4 integers by one position }

int main(int argc, char ** argv) { //TO-DO check if there are 4 inputs. //print out an error message if there are not enough inputs. //hint: use argc int a = atoi(argv[1]); //atoi converts string to int int b = atoi(argv[2]); int c = atoi(argv[3]); int d = atoi(argv[4]); rotate_4(&a, &b, &c, &d); printf("%d %d %d %d ", a, b, c, d); return 0; }

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions