60 583
Assignments Done
97,9%
Successfully Done
In April 2018

Answer to Question #57509 in C for joe

Question #57509
input is n positive numbers and reverse it, out put gv the absolute difference and give the reverse(magic number),using function reverseinteger, and function generate magicnumber
Expert's answer
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

typedef unsigned int ui;
#define base 10

ui reverse_integer(ui a) {
ui b = 0;
do b = (b * base) + (a % base);
while ((a /= base) != 0);
return b;
}

ui generate_magic_number(ui a) {
return reverse_integer(abs(reverse_integer(a) - a));
}


int main() {
ui n; printf("n: "); scanf("%u", &n);
ui size = n * sizeof(ui);
ui* a = malloc(size);
ui* b = malloc(size);
printf("n positive numbers: ");
for (ui i = 0; i < n; ++i) {
scanf("%u", &a[i]);
b[i] = generate_magic_number(a[i]);
}
printf("corresponding magic numbers: ");
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