Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started