Question

In: Computer Science

You must write a C program that prompts the user for numbers and multiplies them using...

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.

Solutions

Expert Solution

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);

}


Related Solutions

C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Write a c++ code that prompts the user to enter three float numbers and print them...
Write a c++ code that prompts the user to enter three float numbers and print them in acsending order
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
Write a C program that prompts the user to enter three sets of five double numbers...
Write a C program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.) The program should accomplish all of the following: a. Store the information in a 3×5 array. b. Compute the average of each set of five values. c. Compute the average of all the values. d. Determine the largest value of the 15 values. e. Report the results. Each major task should...
You will write a program that prompts the user to enter a 7-digit phone numbers, and...
You will write a program that prompts the user to enter a 7-digit phone numbers, and finds the 3- and 4-letter words that map to the phone number, according to the restrictions outlined earlier. A sample run: unixlab% java MapNumbers Enter name of dictionary file: words10683 Enter a test word (3 letters): cat Test word maps to 228 Enter telephone number (7 digits, no 0's or 1's, negative to quit): 2282273 Options for first 3 digits: act cat bat Options...
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT