Answer to Question #57418 in C for joe
input is n positive numbers and reverse it, out put gv the absolute difference and give the reverse(magic number) give a code for this
1
2016-01-22T07:59:12-0500
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
typedef unsigned int ui;
#define base 10
int R(ui a) {
/** to reverse a number **/
ui b = 0;
do b = (b * base) + (a % base); while ((a /= base) != 0);
return b;
}
int main() {
ui n; printf("number of numbers <-- "); scanf("%i", &n);
ui size = n * sizeof(ui);
ui* a = malloc(size);
ui* b = malloc(size);
for (ui i = 0; i < n; ++i) {
scanf("%d", &a[i]);
b[i] = R(a[i]);
b[i] = R(abs(b[i] - a[i]));
}
for (ui i = 0; i < n; ++i)
printf("%d ", b[i]);
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C
Comments
Leave a comment