Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

delay (500) int Punetion (intx, int y) int zesult: zeturn result Parameters pass

ID: 3750953 • Letter: D

Question

delay (500) int Punetion (intx, int y) int zesult: zeturn result Parameters passed to vol t nothing s returned.any C datatype Function name Function int x,int Y) int result Return statement, datatype matches result -declaration. return result: Curty braces required. Homework For following exercises write code a submit conclusions. 1. Create a program in Arduino that input five numbers between 10 and 100, inclusive. As each number is read, display it only if it's not a duplicate of a number already read Display the complete set of unique values entered after the user enters each new value. Use one array to store elements and the function "investigar ( to prove the number is not in the array.See the example below Enter number: 11 Enter number: 85 11 85 Enter number: 26 11 85 26 Enter number: 1 11 has already been entered 11 85 26 Enter number: 41 11 85 26 41 2. Create an array A with five elements, then create two functions in Arduino as detailed below: a. Imprimir O- print all elements of A b. Existe(inrx), given the number "", if x is in A, then print-," era" en A" otherwise, remove the minimum element and add the value x [such that, the array A always has size five) 3. Write a sketch in Arduino with two functions, the first function fin the value in the equation: y+20 given the value x The other function prove if y is an even number. Print all results(hint: use modulo operator %)

Explanation / Answer

1)Solution for first question. The below code should wor fine. Do some modifications if required.

int arr[5]; //initializing array
int number = 0; //initializing number with 0
int length = 0; //initializing length with 0
bool duplicate = false; //set duplicate to false by default

void insebtor(){
  
for(int i=0;i<5;i++){
Serial.print("Enter number: ");
number = Serial.read();
Serial.println();
length = sizeof(myInts)/sizeof(int); //calculatinglength of the array
//finding whether the element entered is duplicate
for(int j=0;j<length;j++){
if(arr[j] == number){
duplicate = true;
break;
}
}
  
if(duplicate){
Serial.print(number);
Serial.println(" has already been entered");
duplicate=false;
}
else
arr[length+1] = number; //adding element in to array if it is not duplicate
  
for(int j=0;j<length;j++){
Serial.print(arr[j]);
Serial.print(" ");
}
Serial.println();
}
}

2) Solution for second question

int arr[5]={31,22,43,74,85};

Imprimir(){

for(int j=0;j< 5;j++){

Serial.print(arr[j]);

Serial.print(" ");

}

Serial.println();

}

Existe(int x){

bool exist = false; //by default let assume element does not exist

int min =0; // assume 0th element as min elemnt in array

//finding whether elemnt already exist in array

for(int j=0;j<5;j++){

if(arr[j] == x){

exist = true;

break;

}

}

if(exist)

Serial.println("ya esta en A");

else{

//finding the minimum element

for(int j=1;j<5;j++){

if(arr[j]<arr[min])

min = j;

}

  

//removing min element and adding the new element

//by replacing min element with new element

arr[min] = x;

}

}

3)Solution for third question


void setup(){
Serial.begin(9600);
}

void loop() {
  
int x = 2;
//if you want to take input from user then use below 2 lines of code instead
//Serial.print("Enter value for x");
//int x =Serial.read();
int y;

y = fin(x);
Serial.println(k);
delay(500);
}

int fin(int x){
int result;
result = x *x + 20;
return result;
}
This is the solution for 3rd question first part. I didnt understoodwhat you are expecting in 2ndpart. Can you please explain in more details. Thanks.. Hope this helps you