0% found this document useful (0 votes)
26 views2 pages

Activity 12

This document provides instructions and problems for an Arduino activity involving arithmetic operators, comparison operators, and looping. [1] The first problem has students modify starter code to print the first 10 odd values of x, even values of y, and squared values of z using a for loop. It also asks them to explain what happens when adding 5,000 to x each iteration and which data type prevents overflow. [2] The second problem has students run code using a for loop to calculate factorials and print the value of i and x after each iteration. It asks what the largest factorial is using a float data type. [3] The third problem asks students to write a for loop and print
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Activity 12

This document provides instructions and problems for an Arduino activity involving arithmetic operators, comparison operators, and looping. [1] The first problem has students modify starter code to print the first 10 odd values of x, even values of y, and squared values of z using a for loop. It also asks them to explain what happens when adding 5,000 to x each iteration and which data type prevents overflow. [2] The second problem has students run code using a for loop to calculate factorials and print the value of i and x after each iteration. It asks what the largest factorial is using a float data type. [3] The third problem asks students to write a for loop and print
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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