Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// I have trouble getting q in this code example can you please explain how can I find it? When I compiled it I got

// I have trouble getting q in this code example can you please explain how can I find it? When I compiled it I got p but it gives me an error when finding q. I have in this case an example that gives me 15 as p, but I have trouble comparing 15 with 51 to figure if it is the exact number. So the main question is how can I get the inverse digits of 15(that is 51) from the code. thanks

#include #include

/*

This program determines whether the value of the global variable x (expressed in hexadecimal notation) is a 16-Harshad number and if so, whether the factors involved are mirrors of each other. That is, if x = p * q, where p = sum of hexadecimal digits of x and q is the reverse of p (same digits in reverse order). For example, 6A5 = 15*51 in base 16.

The program prints a statement indicating which of 3 cases is true: 1) x is not a 16-Harshad number, 2) x is a 16-Harshad number without mirror factors (and gives the factors), or 3) x is a 16-Harshad number with mirror factors (and gives the factors).

*/

unsigned x = 0x6A5; //unsigned x = 0x6A561; int main() { unsigned p=0x0; unsigned q=0x0;

//this is going to be my part

//unsigned y=0x0000000f & x; //printf("%#x is my practice: ",y); unsigned y=0x00; unsigned z=0x00; unsigned number=x; unsigned numarray [7]; int counter=0; //here I put all the values of x in a single array to be able to add it and compare it while (number != 0) { y=0x0000000f & number; number=number>>4; numarray[counter]=y; counter++; printf("%#x is y: ",y); } //p=numarray[0]+numarray[1]+numarray[2]+numarray[3]+numarray[5]+numarray[6]+numarray[7]; // p=numarray[0]|numarray[1]|numarray[2]|numarray[3]|numarray[4]|numarray[5]|numarray[6]|numarray[7];

//Here I add the x values and get p int counter2=0; while(counter2 != counter) { p=p+numarray[counter2]; counter2++;

}

unsigned qnum=p; unsigned qarray[7]; int counter3=0;

while(qnum != 0) { z=0x0000000f & qnum; qnum=qnum>>4; qarray[counter3]=z; counter3++;

printf("%#x is z: ",z);

}

//unsigned q=x/p;

//a=0x0000000f & newx;

//if(x % p==1){

//printf("%#x is not a 16-Harshad number. ", x);

//}

//if(qarray[0]==a){

// printf("%#x is a 16-Harshad number, w/ mirror factors: %#x * %#x ", x, p, q ); //}

//else // printf("%#x is a 16-Harshad number, w/out mirror factors: %#x * %#x ", x, p, q ); // your program should use these print statements // printf("%#x is not a 16-Harshad number. ", x); // printf("%#x is a 16-Harshad number, w/out mirror factors: %#x * %#x ", x, p, q ); // printf("%#x is a 16-Harshad number, w/ mirror factors: %#x * %#x ", x, p, q ); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

LO1 Identify why performance management is necessary.

Answered: 1 week ago