Question

You must write a C program that prompts the user for two numbers (no command line...

You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for correct input if necessary. The program must require the user to enter a specific character to exit the program and return 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 multiples 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 6000 times 6000 should need 32 bits. • You may NOT use any libraries other than stdio.h • You may NOT use the multiplication operator or the division operator o Use bitwise shifting to halve and double numbers o Use modulus to detect if a value is even or odd • You must use two source files o One source file will contain the main() function, global variables, and proper function prototypes. o The other source file will contain all other functions as specified below o The program must be built using the compile command like Tutorials Point (pdf p27 – end of Chapter 8) • You must have at least the following four functions in addition to main o One function that prints your logo banner o One function that takes in a value and prints it in binary format o One function that prompts the user for input and qualifies those values o One function that takes in the two values, multiplies them and returns the result. • Your program must keep the two input values and the result in global variables • There can be no “magic numbers” in the code o Any constants must be defined with a Macro

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program :


#include <stdio.h>
#include <stdint.h>

int alarusse_multiplication(int,int);

int main(void){
int run = 1;
int choice;
int multiplicand = 1;
int multiplier = 1;
int result = 1;
printf("|-------------------------------------------------|\r\n");
printf("|-------------Multiplication Program---------------|\r\n");
printf("|-------------------------------------------------|\r\n");
  
while(run){
printf(" 1. For Multiplication \r\n 2. For Exit \r\n Enter Choice:\r\n ");
fflush(stdin);
scanf("%d",&choice);
switch(choice){
case 1:
printf(" Enter multiplicand between 0 to 6000 \r\n ");
fflush(stdin);
scanf("%d",&multiplicand);
printf("Enter multiplier between 0 to 6000 \r\n ");
fflush(stdin);
scanf("%d",&multiplier);
result = alarusse_multiplication(multiplicand,multiplier);
printf("Result is %d \r\n ",result);
break;
case 2 :
run = 0;
printf("Exit...!! Good Bye!!\r\n");
break;
default:
printf("Error !! Invalid Options\r\n");
break;
}
}
return 0;
}


int alarusse_multiplication(int m,int n){
int result = 0;
  
if(n > m){
int temp = 0;
temp = m;
m = n;
n = temp;
}
  
while(n > 0)
{
if(n % 2 != 0)
{
result += m;
}
m *= 2; // double the first number   
n /= 2; // half the second number
}
  
  
return result;
}
Output:
|-------------------------------------------------|
|-------------Multiplication Program---------------|
|-------------------------------------------------|
1. For Multiplication
2. For Exit
Enter Choice:
1
Enter multiplicand between 0 to 6000
123
Enter multiplier between 0 to 6000
321
Result is 39483
1. For Multiplication
2. For Exit
Enter Choice:
2
Exit...!! Good Bye!!

Add a comment
Know the answer?
Add Answer to:
You must write a C program that prompts the user for two numbers (no command line...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are required to write an interactive program that prompts the user for seven (7) real...

    You are required to write an interactive program that prompts the user for seven (7) real numbers and performs the following tasks: Reads and stores the numbers into one-dimensional array called A. Calculates the sum of the numbers. Find the average of the numbers. Finds the smallest value of the numbers. Prints all the results with proper headings. Program requirements: -     The program must contain at least five functions using necessary parameters. These functions should read the data, perform the...

  • Write a program that prompts the user to read three positive hex integers and display their...

    Write a program that prompts the user to read three positive hex integers and display their sum in both hex and decimal. Your program should prompt the user to read the number again, if the input is incorrect. You must use java.lang.NumberFormatException. (chapter12.AddThreeHexNumbers.java)

  • Write a C++ program that prompts the user to enter two numbers. Then prompt the user...

    Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • Write an ARM program that implements a simple four-function calculator and prompts the user to enter...

    Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B                             ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...

  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write an ARM program that implements a simple four-function calculator and prompts the user to enter...

    Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B                             ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...

  • Write a program that prompts the user to input three numbers

    Write a program that prompts the user to input three numbers. The program should then output the numbers in non-descending order

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT