60 745
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #57418 in C for joe

Question #57418
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
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions