Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 INTRO. TO ELECTRICAL AND COMPUTER ENG. ECE5: HOMEWORK #2 Exercise 2 (Functions). Write 3 functions, all of them taking as input an integer between
1 INTRO. TO ELECTRICAL AND COMPUTER ENG. ECE5: HOMEWORK #2 Exercise 2 (Functions). Write 3 functions, all of them taking as input an integer between 0 and 9999, with the following functionalities: Note. Recall that the operator % returns the remainder of integer division. For example, 10 % 3 returns 1. 1. The function get Thousands () should return the thousands digit of the number, e.g., x-get Thousands (2345); 1 should assign to x the number 2. 2. The function getOnes() should return the ones digit of the number; e.g., x=getones (2345); 2 should assign to x the number 5. 3. The function getTens() should return the tens digit of the number, e.g., x=get Tens (2345); should assign to x the number 4. 4. The function getHundreds() should return the hundreds digit of the number; e.g., x=get Hundreds (2345); should assign to x the number 3. 5. Test you functions using the following sketch /* your functions go here */ void setup() { int n = 6789; Note. The functions Serial.print("text") and Serial.println("text") both display the string text into a computer connected to the Arduino through the USB port. However, the latter adds a "newline" command, meaning that subsequent calls to Serial.print and/or Serial.println appear in the next line. Serial.begin(9600); 11 12 Serial.print("thousands: "); Serial.println(get Thousands (n)); Serial.print ("hundreds : "); Serial.println(get Hundreds (n)); Serial.print("tens: "); Serial.println(getTens (n)); Serial.print("ones: "); Serial.println(getones (n)); 13 14 15 17 } 19 20 void loop() { } 21
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started