Question: Lab 1 : Basic Math Due: 1 / 2 7 / 2 1 In this lab you will practice basic math operations in C +
Lab : Basic Math Due:
In this lab you will practice basic math operations in C First you will review a program that demonstrates the
use of basic math, then you will write your own C code that uses basic math.
Example Program
Our example program is about the Dateable Equation. There is a common rule of thumb that you should not
date a person who is younger than seven plus your age divided by two. The Dateable Equation is:
DateableAge YourAge
The labexample.cpp program calculates the lowest dateable age for a given person's age. Open this program
in a C IDE Integrated Development Environment Read and understand the code and run the program. Try
changing the given age to see the dateable age for different ages.
Notice that the Dateable Age is always an integer. If your age is an odd number, dividing it by two should result
in a decimal number, so why is the Dateable Age always an integer? The reason is that in C when you divide
two integers the result is an integer the decimal part is truncated Even if the dateable variable was of type
double, the result of the division would not have a decimal part. In order to have a decimal result from division,
at least one of the numbers involved in the division must be a floating point number such as type double and if
we are saving the result into a variable, the variable must be a floating point type. In this case an integer is the
correct result because we always deal with ages as whole numbers. But in other cases integer division will give
an incorrect result. In another lab we will look at an example where integer division results in an incorrect
result.
Your Program
In this program you will calculate your magic number. Your magic number is calculated by multiplying the
month of your birth by the year of your birth, and taking the modulus of that result and the day of your birth.
The equation is:
MagicNumber month year day
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
