cycle instructions, vectors (arrays), matrices (two-dimensional arrays) and functions. Students should develop a top-down approach to building programs by organizing them into roles.
The simplicity of the solutions is valued, which, however, must meet the requirements of the statement. The compilation of programs must not generate warnings, the variable names must describe their purpose and all values read from the keyboard must be validated.
The use of “magic numbers” in the code should be avoided and the definition of constants using the #define directive is recommended.
The student must mention the websites that he consulted when carrying out and implementing the work's questions.
Questions
1. Consider the BIG_INT type, used to perform operations with integers up to 255 digits.
#define MAX_DIGITS 255
typedef unsigned char byte;
typedef byte BIG_INT [MAX_DIGITS + 2];
The array is used to represent the BIG_INT as indicated in Figure 1.
The value present at index 0 indicates the number of digits that BIG_INT contains, at index 1 the sign of the number (1 indicates a positive and 0 a negative number) and from of index 2
1)
/**
* Description:
* The function calculates the multiplication between two BIG_INT and stores the result in the third BIG_INT,
* taking into account the BIG_INT sign
* Parameters:
* b1 - first operand BIG_INT
* b2 - second operand BIG_INT
* bm - BIG_INT which stores the result
* Return:
* The function returns false if there is an overflow, otherwise it returns true.
*/
so far ive done this
bool big_mul( const BIG_INT b1, const BIG_INT b2, BIG_INT bm )
{
BIG_INT baux;
int carry=0;
int r;
for (int i=2;i<b2[0]+1;i++)
{
for(int i=2;i<b1[0]+1;i++)
{
r=b2*b1+carry;
if(r>9)
{
baux=r%10;
carry=r/10;
}
else{
baux=r%10;
carry=0;
}
}
if (big_size (bm)>255)
{
return false;
}
else
{
return true;
}
}
big_add_aux(bm,baux,bm);
return 0;
}
But it doesnt seem to be working, can you help me understand this please!
The simplicity of the solutions is valued, which, however, must meet the requirements of the statement. The compilation of programs must not generate warnings, the variable names must describe their purpose and all values read from the keyboard must be validated.
The use of “magic numbers” in the code should be avoided and the definition of constants using the #define directive is recommended.
The student must mention the websites that he consulted when carrying out and implementing the work's questions.
Questions
1. Consider the BIG_INT type, used to perform operations with integers up to 255 digits.
#define MAX_DIGITS 255
typedef unsigned char byte;
typedef byte BIG_INT [MAX_DIGITS + 2];
The array is used to represent the BIG_INT as indicated in Figure 1.
1)
/**
* Description:
* The function calculates the multiplication between two BIG_INT and stores the result in the third BIG_INT,
* taking into account the BIG_INT sign
* Parameters:
* b1 - first operand BIG_INT
* b2 - second operand BIG_INT
* bm - BIG_INT which stores the result
* Return:
* The function returns false if there is an overflow, otherwise it returns true.
*/
so far ive done this
bool big_mul( const BIG_INT b1, const BIG_INT b2, BIG_INT bm )
{
BIG_INT baux;
int carry=0;
int r;
for (int i=2;i<b2[0]+1;i++)
{
for(int i=2;i<b1[0]+1;i++)
{
r=b2*b1+carry;
if(r>9)
{
baux=r%10;
carry=r/10;
}
else{
baux=r%10;
carry=0;
}
}
if (big_size (bm)>255)
{
return false;
}
else
{
return true;
}
}
big_add_aux(bm,baux,bm);
return 0;
}
But it doesnt seem to be working, can you help me understand this please!