I am writting these in C/C++, any help on either one is greatly appreciated 1) C
ID: 671622 • Letter: I
Question
I am writting these in C/C++, any help on either one is greatly appreciated
1) Create a function f_rotate that takes integers n and r as input and returns another integer which is a rotation of r by n positions. For example, for n = 24579 and r = 2, your function should return 79245.
2) Create a function f_cubes_sum that takes an integer n and returns any pair of integers a and b which satisfies a3 + b3 = n, for a 0 and b 0. If such a pair does not exist, your function should return NULL. In this problem you will have to allocate memory dynamically for the pair and return a pointer to it. Remember that the caller will be responsible for deallocating this memory.
Explanation / Answer
int f_rotate(int val, int r){
while(r--){
int d = val%10;
val = val/10;
int x = 10;
while( x < val) x *= 10;
val = d*x + val;
}
return val;
}
//////////////////////////
int** f_cubes_sum(int n){
int **p;
for(int i = 0; i*i*i <= n ; i++)
for(int j = i; j*j*j <= n ; j++) if(i*i*i + j*j*j == n ) { *p = i, *(p+1) = j; return p;}
return NULL;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.