In: Computer Science
You must write a C program that prompts the user for numbers and multiplies them using "a la russe" multiplication. No input is allowed at execution time (no command line input). The program MUST DISPLAY YOUR BANNER LOGO as part of a prompt to the user. A menu must allow the user to put in two numbers at the same time or each of two numbers one at a time. The valid range of values for each number is 0 to 5000. YOU MAY ASSUME that the user will always enter numerical decimal format characters at the keyboard. Your program should check this numerical range (INCLUDING CHECKING FOR NEGATIVE NUMBERS) and re-prompt the user for correct input if necessary. The program must also require the user to enter a specific character of your choice to exit the program and return the main() function back to the terminal prompt. The program should print the result in decimal format AND binary format. The binary output should use the least number of bits to display the number in multiple of 8 bits. I.e., anything less than 256 should display as 8 bits, anything less than 64k should use 16 bits, etc. The value 5000 times 5000 should need 32 bits. *YOU MAY NOT USE ANY LIBRARIES OTHE THAN stdio.h * YOU MAY NOT USE THE multiplication operator or division operator. Use bitwise shifting to halve and double numbers Use modules to detect if a value is even or odd *You must use two source files and one header file The header file must contain all MACRO's and function prototypes One source file will contain the main()function, and any global variables. The other source file will contain all other functions as specified below. The program must be built using the compile command like Tutorials Point pdf p27 *You must have at least the following four functions in addition to main One fucntion that prints your logo banner One function that takes in a value and prints it in binary format One function that prompts the user for input and qualifies those values One function that takes in the two values, multiplies them and return the resluts. *Your program must keep the two input values and the result in global variables *There can be no “magic numbers” in the code Any constants must be defined with a Macro Hint: You will likely need a while loop to process the values during the multiplication algorithm. Use printf() statements liberally throughout the code (especially within loops to display data to the screen during execution). Display all relevant values during the algorithm to analyze what is happening during your program. When the code is working, comment out the printf() statements, but do not erase them. Leave them there in case you want to enable them for further debugging later.
Code:-
#include <stdio.h>
long binary_conversion(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * binary_conversion(num / 2);
}
}
int main()
{
int f;
int s;
int result=0;
int shiftAmount=0;
char choice=' ';
while(1){
result=0;
printf("\nEnter m for calculator or x for exit : ");
scanf("%c",&choice);
while(choice=='\n'){
scanf("%c",&choice);
}
if(choice=='m'){
printf("Enter the first number : ");
scanf("%d",&f);
printf("Enter the second number : ");
scanf("%d",&s);
while(f!=0){
if(f%2==0){
printf("The first column (%d) is even\n",f);
}else{
printf("The first column (%d) is odd\n",f);
result += s;
}
printf("BEFORE SHIFT First = %d, Second = %d, Result = %d\n",f,s,result);
if(f%2!=0){
f = f-1;
}else{
f = f>>1;
s =s<<1;
}
shiftAmount+=s;
printf("AFTER SHIFT First = %d, Second = %d, Result = %d\n",f,s,result);
}
printf("Final result of first times second is : %d decimal = 0b_",result);
int c;
int k;
if(result<=256){
c = 8;
}else if(result<=4000){
c = 16;
}else{
c = 31;
}
for (; c >= 0; c--)
{
k = result >> c;
if (k & 1)
printf("1");
else
printf("0");
}
}else{
break;
}
}
return (0);
}