Question: Re-write the program, but this time the variables for the two numbers (input1 and input2) and the result must be kept in local variables defined

Re-write the program, but this time the variables for the two numbers (input1 and input2) 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.

The program is in two parts:

Main part:

#include

#include "secondsource.h"

int input1;

int input2;

int result;

int shift;

char choice;

int Bitvalue; int k;

int main()

{

banner();

prompt(); alaRusse(); printBinary();

return 0;

}

Second Source:

#include

#define MAXRANGE (4000)

#define EIGHTBITMAX (256) #define SIXTEENBITMAX (65536)

#define ZERO (0) #define ONE (1) #define TWO (2)

#define EIGHT (8) #define SIXTEEN (16) #define TWENTYFOUR (24)

extern int input1; extern int input2; extern int result; extern int shift; extern char choice; extern int Bitvalue; extern int k;

void banner() {

printf("# ______________|| \\\\ # "); printf("# |********** ______________|| \\\\ # "); printf("# |********** ______________||(_)\\\\ # "); printf("# |********** ______________||____\\\\ # "); printf("# |********** ______________||\\\\ # "); printf("# |********** ______________|| \\\\ # "); printf("# |_________________________|| _\\\\ # "); printf("# |_________________________||(_)\\\\ # "); printf("# |_________________________||____\\\\ # "); }

void printBinary() {

if(result <= EIGHTBITMAX) { Bitvalue = EIGHT;

} else Bitvalue = SIXTEEN; for (; Bitvalue >= ZERO; Bitvalue--)

{

k = result >> Bitvalue;

if (k & ONE)

printf("1");

else {

printf("0");

}

} } void prompt(){} void alaRusse() { while(1) {

result;

printf(" Enter m for calculator or x for exit : ");

scanf("%c",&choice);

while(choice==' ') {

scanf("%c",&choice);

}

if(choice=='m') {

printf("Enter the first number : ");

scanf("%d",&input1);

printf("Enter the second number : ");

scanf("%d",&input2);

while(input1 != ZERO) {

if(input1 % TWO == ZERO) {

/*printf("The first column (%d) is even ", input1);*/

} else {

/*printf("The first column (%d) is odd ",input1);*/

result += input2;

}

/*printf("BEFORE SHIFT Input1 = %d, Input2 = %d, Result = %d ", input1, input2, result);*/

if((input1 % TWO) != ZERO) {

input1 = input1 - ONE;

} else {

input1 = input1 >> ONE;

input2 = input2 << ONE;

}

shift += input2;

/*printf("AFTER SHIFT Input1 = %d, Input2 = %d, Result = %d ", input1, input2, result);*/

}

printf("Final result of first times second is : %d decimal = 0b_", result); printBinary();

} else break; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!