You are on page 1of 2

1

ATG 1008 Activity 12

Read This First:


Each person is required to upload a completed activity online. Use the Activity 12 Template.docx
(located on moodle) to submit your answers.

Learning objective(s):
In this activity you will become familiar with arithmetic operators
• Arithmetic operators:
o +, -, *, /
o ++, --, +=, -=, *=, /=
• Comparison operators:
o ==, !=, <, <=, >, >=
• Looping:
o for( )

Deliverable:
Please answer the following problems within one (1) PDF file (no attachments). (40 marks total)

Problems:
1. Open the arithmetic_0.ino file and run the program. Observe the serial monitor output.
a. Modify the code to print out the first 10 odd values of x, first 10 even values of y, and
the first 10 squared value of z (12,22,32, etc.). Start at 1 for x, and 0 for y and z and copy
and paste the revised code as your answer. (10 marks)

b. Add 5,000 to x variable every time through the loop. What happens? Why? (4 marks)

c. Modify the x variable data type so the above issue doesn’t happen. What data type did
you need? (2 marks)

2. Comment out the code from the previous question and un-comment the following lines of
code:
x = 1;
for(i=1; i<=5; i++)
{
x = x * i;
}
Serial.print(i-1);
Serial.print("! = ");
Serial.print(x);
Serial.println(" | correct?");

What are the values of i and x after each individual time (iteration) through the for( ) loop?
Write out what is happening in this loop. What is the largest factorial that can be calculated
using a float data type for x? (Use a factorial calculator to check your solution.) (10 marks)
2
ATG 1008 Activity 12

3. Write your own code using a for( ) loop and arrays to calculate 10 solutions to the following
equation:

𝑥 = 1, … , 10
𝑦 = (0.5 ∗ 𝑥)/𝑧 {
𝑧 = 5, … , 14

Have each value of y print on a new line in your serial monitor like this “y= 0.1 for i = 0 “ (Hint:
this shows the first value of y associated with i). Copy and paste your code and the output of
your serial monitor into your report. (14 marks)

You might also like