Questions   
Sort: 
 #2
avatar+63 
+1
Feb 10, 2019
 #4
avatar+845 
0
Feb 10, 2019
 #2
avatar+2489 
+3

Here’s a basic outline for your assignment. The actual coding depends on the language used.

 

Define and Create arrays: Numeric N(300,2), String BC(300,20). The first is a 2-dimeintional numeric array (named N) with two columns of 300 elements.  The second is a string array (named BC) of 20 columns of 300 elements.

 

Generate numbers from 1 to 300 (base 10). Store these numbers sequentially in column (1) of array N(i,1)   “N” is the name of the array and (i) is the location in the array, and the (1) means the first column.

 

Using a sequential loop process, square the number stored in array N(i,1) and store it in array N(i,2).

 

Call subroutine Base Number Conversion.

 

This will be the most complex part of your program. Here, your code will convert and  populate the string array with the base_b equivalent of the number (N2) storing it in the location determined by (i). 

 

BC(i,1) is the index and the number N. BC(i,10) will be the base 10 location. This will not require a base conversion but may (depending on the language used) need to be explicitly converted to a string format to store it here.

 

The other columns will have the square of this Number in the corresponding bases.  BC(i,2) is the location for N2 in base 2 (binary).  BC(i,3) is the location for N2 in base 3. BC(i,4) is the location for N2 in base 4, etc.

 

There are several algorithms for converting a decimal number to base (b).

Some languages have built-in subroutines for the common Hex and Binary base conversions, and some will do any base up to base 64.  Your teacher/professor will probably want you to write your own code for these conversions.

 

The easiest method that’s conveniently suitable is the divide, subtract and multiply method.

Create a 20 element array to store the remainders. (The largest string will be 17 characters for the conversion of N=300; 3002 = 9000010 = 101011111100100002)

 

For any given base, the elements of the array will store the decimal value of each digit of base (b).  The values are stored ascending in base 10, but the implied value for each element is

[D1 * b0] [D2 * b1], [D3 * b2], [D4 * b3], [D5 * b4], ..., ect where b is the base

 

Here’s an example converting 71298 (the square of 267) to base 17.

You can code separate subroutines for each base, or increment an index variable for the base divisor. The process is the same for each base.  . 

This is gives a sequential overview of how the variable data in the loop would present if they were examined at each step of the loop. These are the same lines of code repeated until a zero integer is returned. It is four times for this example.   

 

Divide: 71298/17 = 4193.470588235 | separate the integer and fractional portions.

Subtract: 4193.470588235 -4193 = 0.470588235  | giving fractional portion

Multiply: 0.470588235 * 17 =  8  | Store in D1   (8 * 170) <-- implied base 17

 

Divide: 4193/17 = 246.6470588235

Subtract: 246.6470588235-246 = 0.6470588235

Multiply: 0.6470588235 * 17 = 11 | Store in D2    (11 * 171)

 

Divide: 246/17 = 14.47058823529

Subtract: 14.47058823529 - 14 =  0.47058823529

Multiply: 0.47058823529 * 17 = 8 | Store in D3    (8 * 172)

 

Divide: 14/17 = 0.82352941176

Subtract: 0.82352941176- 0 =  0.82352941176

Multiply: 0.82352941176 * 17 = 14 |store this in D2   (14 * 173)

 

End subroutine here if integer is (0). Then Convert and concatenate the numeric characters, then store in string array BC(N,B).  

When a value exceeds (910) A, B, C will be used in its stead.

Read values in array D(p) |where p is the index position and p=1 is the least significant digit.

Test value:

If D(p) < 10 then move D(p) to C(p) array. |IF a number less than 10 then move the number.

Else

V=D(p) -10 on V move “A” , “B”, “C”, ect to C(p) | If a number greater than 9 then move the corresponding letter to concatenation array.

 

The “8” is copied as is, and 14 corresponds to “E” and 11 corresponds to “B”  

After the loop completes, reverse the string so the lesser significant digits are to the right of the more significant digits, then store in string array BC(276,17).  The language you use may have a library function to do this. The alpha-numeric number stored is E8B8

 

Remember to clear the temporary concatenation array after each call to the subroutine; else you will have rubbish in some of your conversions.

 

Go to next loop for next base, do the same bloody thing until the base is greater than 20.

Then Loop  until N > 300

 

After the main array is populated with the data, then it is a simple matter to look for numerical palindromes. The language you use may have a library function to reverse the string, or use the same code used in the convert and concatenate subroutine.  Compare these two strings, if they match then move the relevant data to the screen or print array  

 

This basic explanation of the algorithms involved may give the impression this is complicated, but this is simple to code. 

 

----------

 

 

 

GA

Feb 10, 2019
 #2
avatar+845 
0
Feb 10, 2019

2 Online Users

avatar