Write a program which can accept binary numbers and certain operations to calcul
ID: 3808317 • Letter: W
Question
Write a program which can accept binary numbers and certain operations to calculate the results of those operations. The user should see something like: Enter a 16 bit unsigned binary number: Enter operator (+, -, *, %/, | &^E) Enter a 16 bit unsigned binary number: The answer is: Enter operator (+, -, *, %/, | &^E) Enter a 16 bit unsigned binary number: The answer is: (this should perform the operation on the previous answer and the newly entered number) The program should continue in this manner, until E is entered as the operator. When E is entered, the program should terminate. Follow the process: List the inputs & outputs Design an algorithm to solve this problem in either pseudocode or with a flowchart (2 point extra for a good flowchart) Verify the algorithm works Write the program Test the program with a good set of inputs and demonstrate that it is workingExplanation / Answer
I have written a program with accepts the 2 binary numbers along with the operator function to be performed as input and then convert them to decimals and performs operation and gives the result as output. i have include 4 operators in switch case you can added the remaining as well by editing the cases.
void main()
{
int a,b, binary_val, dec_vala = 0,dec_valb=0, base = 1, rem,res=0;
int ch;
printf("Enter a binary number1(1s and 0s) ");
scanf("%d", &a);
a= num;
while (num > 0)
{
rem = num % 10;
dec_vala = dec_vala + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("The Binary number is = %d ", a);
printf("Its decimal equivalent is = %d ", dec_vala);
}
printf("enter another binary number(1s and 0s) ");
scanf("%d",&b);
b= num;
while (num > 0)
{
rem = num % 10;
dec_valb = dec_valb + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("The Binary number is = %d ", b);
printf("Its decimal equivalent is = %d ", dec_valb);
}
printf("enter operator (+, -,*,%) press E to exit");
scanf("%d",&ch);
switch(ch)
{
case +: res=dec_vala+dec_valb;
break;
case -: res=dec_vala-dec_valb;
break;
case *: res=dec_vala*dec_valb;
break;
case %: res=dec_vala/dec_valb;
break;
case E:exit(0);
default: printf(“Wrong choice!!nPress any key…”);
getch();
exit(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.