Question
Re-write Homework 4, but this time the variables for the two numbers and the result must be kept in local variables defined in the main
Re-write Homework 4, but this time the variables for the two numbers and the result must be kept in local variables defined in the main function. And none of these variables may be returned from a function call. This means that to change the value in these variables, they must be passed by reference to a function and the function must update the value at the variables address location.
(I need the answer for C language and i use Cygwin GCC 7.3.0.)
homework 4:
#include
#define EIGHTBITMASK (0b10000000)
#define SEVEN (7)
#define ZERO (0)
#define ONE (1)
#define SIXTEENBITMASK (0b1000000000000000)
#define TWENTYFOURBITMASK (0b100000000000000000000000)
#define FOURTHOUSAND (4000)
#define TWO (2)
#define SIXTEEN (16)
#define TWOHUNDREDFIFTYFIVE (255)
#define EIGHT (8)
#define TWENTYFOUR (24)
#define SIXTHOUSANDFOURHUNDREDNINETYNINE (6499)
#define SIXTYFOURTHOUSAND (6400)
int num_1;
int num_2;
int result;
void ALSAAD()
{
int a, b, c, d, e, f, g, h, temp;
a = printf( " ");
b = printf( " #### ## ### #### #### ### ");
c = printf( " # # ## ## # # # # # ## ");
d = printf( " #### ## ## #### #### # ## ");
e = printf( " # # ## ## # # # # # ## ");
f = printf( " # # ## ## # # # # # ## ");
g = printf( " # # ###### ### # # # # ### ");
h = printf(" MOHAMMAD ALSAAD #1001692764 ");
temp = a+b+c+d+e+f+g+h-8;
}
void convertbinary(unsigned long bin)
{
unsigned long memory = ZERO;
int i= ZERO;
printf("0b");
if (result > ZERO && result < TWOHUNDREDFIFTYFIVE)
{
do
{
memory = bin & EIGHTBITMASK;
if (memory)
{
printf("1");
}
else
{
printf("0");
}
bin<<= ONE;
i++;
}
while (i < EIGHT);
}
else if (result > TWOHUNDREDFIFTYFIVE && result < SIXTYFOURTHOUSAND)
{
do
{
memory = bin & SIXTEENBITMASK;
if (memory)
{
printf("1");
}
else
{
printf("0");
}
bin<<= ONE;
i++;
}
while (i < SIXTEEN);
}
else if (result > SIXTYFOURTHOUSAND)
{
do
{
memory = bin & TWENTYFOURBITMASK;
if (memory)
{
printf("1");
}
else
{
printf("0");
}
bin<<= ONE;
i++;
}
while (i < TWENTYFOUR);
}
}
int alarusse(int x, int y)
{
if (x>y)
{
while (y >= ONE)
{
if (y% TWO != ZERO)
result += x;
x <<= ONE;
y >>= ONE;
}
printf(" %d ", result);
convertbinary( result);
return result;
}
else if (y>x)
{
while (x >= ONE)
{
if (x % TWO != ZERO)
result += y;
y <<= ONE;
x >>= ONE;
}
printf(" %d ", result);
convertbinary(result);
return result;
}
else
{
while (x >= ONE)
{
if (x % TWO != ZERO)
result += y;
y <<= ONE;
x >>= ONE;
}
printf(" %d ", result);
convertbinary(result);
return result;
}
}
int main ()
{
ALSAAD();
printf(" Welcome to multiplication 'a la russe'! ");
printf(" Please Enter your first number: ");
while(scanf("%d",&num_1) != ONE)
{
printf(" Enter a Decimal number between 0 and 4000: ");
while(getchar() != ' ');
}
while ((num_1 > FOURTHOUSAND) || (num_1 < ZERO))
{
printf(" Enter a Decimal number between 0 and 4000: ");
scanf( "%d", &num_1);
convertbinary(num_1);
}
printf("\t Your first number is: %d ",num_1);
printf(" Please enter your second number: ");
while(scanf( "%d",&num_2) != ONE)
{
printf(" Enter a Decimal number between 0 and 4000: ");
while(getchar() != ' ');
}
while ((num_2 > FOURTHOUSAND) || (num_2 < ZERO))
{
printf(" Enter a Decimal number between 0 and 4000: ");
scanf("%d", &num_2);
}
printf("\t Your second number is: %d ",num_2);
alarusse(num_1,num_2);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started