Question

For certain values of float a and float b, expressions (a + b)*10 and a*10 +...

For certain values of float a and float b, expressions (a + b)*10 and a*10 + b*10 can differ by more than 20% even when both a and b are of the same magnitude. Please provide a program in C with variables a and b that confirm this claim.
You must prove the statement without going out of bounds! I.e. a*10 or b*10 or (a+b)*10 should never exceed the max/min floating-point value.

Demo run:

a=...
b=...
(a+b)*10 = ...

a*10 + b*10 = ...

Difference: xx%

Requirements: your solution must match the demo run. Values a and b must be of the same magnitude and not extreme (i.e. should not be too small or too big).

Hints: you might want to use %e specifier in your program.

Two numbers of the same order of magnitude have roughly the same scale: the larger value is less than ten times the smaller value.
This means Bigger_Number / Smaller_Number < 10
This also applies to negative numbers: -20 and 3 are of the same magnitude!

the % difference of two numbers?
The formula is: (Bigger_Value-Smaller_Value)*100/Smaller_Value
If you compare 15 and 10, you'll have (15-10)/10 = 0.5 or 50%.

Homework Answers

Answer #1

SOLUTION

​INPUT $ OUTPUT

CODE FOR GIVEN PROBLEM:

#include <stdio.h>

int main()
{
float a,b,c,d,xx;
a = 33.333333;
b = 66.666666;
c = (a+b)*10;
d = a*10 + b*10;
xx = c - d;
printf("%e\n",xx);
return 0;

}

Know the answer?
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
Similar Questions
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
A school counselor in a high school would like to try out a new conflict-resolution program...
A school counselor in a high school would like to try out a new conflict-resolution program to reduce aggressiveness in students. She first surveyed 16 students using a 20-item instrument to measure their levels of aggression (on a scale of 0 to 10, with higher numbers meaning higher aggression levels). One month after the conflict resolution program was implemented, the students were given the same survey. The data are listed in the table below. The school counselor/researcher has set the...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
a. If variance of asset A is 0.04 and variance of asset B is 0.02, what...
a. If variance of asset A is 0.04 and variance of asset B is 0.02, what is the correlation between the two assets? Assume covariance between the 2 assets to be 0.015. Show how you found the values. b. Suppose a portfolio has expected return of 15% and volatility of 30%. How can you combine this portfolio with the risk-free asset to create a portfolio with 10% expected return? Risk-free asset has expected return of 3%.  Show how you found the...
B. Dr. Quisling, a child psychologist, investigates play behavior in 4-year-olds. She is particularly interested in...
B. Dr. Quisling, a child psychologist, investigates play behavior in 4-year-olds. She is particularly interested in how young girls develop ideas about the gender appropriateness of certain toys. She conducts an experiment in which participants (4-year old girls) first interact with an adult for 10 minutes in a lab playroom. The adult models play for the child by interacting with a female-stereotyped toy (a Barbie doll), a male-stereotyped toy (a dump truck) or a gender-neutral toy (Legos). The children are...
[PART ONE OF PROJECT, ALREADY COMPLETED] An accumulator is a primitive kind of calculator that can...
[PART ONE OF PROJECT, ALREADY COMPLETED] An accumulator is a primitive kind of calculator that can evaluate arithmetic expressions. In fact, the Arithmetic-Logic Unit (ALU) of the rst computers was just an accumulator. An arithmetic expression, as you know, consists of two kinds of tokens: operands and operators All our operands will be (float) numbers and for a start, we shall use only two operators: + (plus) and - (minus) A sample run of the program would look like this....
Answer the following questions given the following call option prices on Google (GOOG) and on Apple...
Answer the following questions given the following call option prices on Google (GOOG) and on Apple (APPL). Note that these are actual option prices on 2/21/13 and these contracts have 60 days till expiration. The 2-month T-bill rate is about 4.75%. Attach all work with your report. OPTION STRIKE EXP VOL LAST GOOG 800 APR 378 28.20 S=795.53 690 APRI 53 101.57 APPL 450 APR 530 18.55 S=446.06 480 APR 856 7.81 Part One Estimate the theoretical option values for...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...