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:
(I need the answer for C language and I use Cygwin GCC 7.3.0.)
Main file:
#include
#include "secondsource.h"
int input1;
int input2;
int result;
int shift;
char choice;
int Bitvalue; int k;
int main()
{
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 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
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