In: Computer Science
SWITCH CASE, WHILE, DO WHILE STRUCTURES, using ARDUINO. Urgent Please! Implement the following programs, attach a flow chart, and photos of its operation. 1. Read a number that represents the month and say what months it is. 2. Using the conditional "while" calculate the factorial of a number 3. Using the “do-while” conditional, make a program that prints all numbers from 1 up to a maximum number entered by the user.
PROGRAM 1:
void setup() {
Serial.begin();
// modify it according to yourself
}
void loop() {
Serial.println("Input Month No :");
int mon_num=Serial.read();
switch(mon_num)
{
case 1:
Serial.println("January");
break;
case 2:
Serial.println("February");
break;
case 3:
Serial.println("March");
break;
case 4:
Serial.println("April");
break;
case 5:
Serial.println("May\n");
break;
case 6:
Serial.println("June");
break;
case 7:
Serial.println("July");
break;
case 8:
Serial.println("August");
break;
case 9:
Serial.println("September");
break;
case 10:
Serial.println("October");
break;
case 11:
Serial.println("November");
break;
case 12:
Serial.println("December");
break;
default:
Serial.println("INvalid Input");
break;
}
PROGRAM 2
void setup() {
Serial.begin();
// modify it according to yourself
}
void loop() {
int n;
Serial.println("ENTER A NUMBER:");
n=Serial.read();
int fact = 1;
while(n>1)
{
fact=fact*n;
n--;
}
Serial.println(fact);
}
FLOWCHART
PROGRAM 3
void setup() {
Serial.begin();
// modify it according to yourself
}
void loop() {
int n;
Serial.println("Enter number of elements you want to enter:");
n=Serial.read();
int a[n];
int max = -99999;
int i = 0;
do{
Serial.println("ENTER NUMBER:");
Serial.println(i+1);
a[i]=Serial.read();
if(a[i] > max)
{
max=a[i];
}
i++;
}while(i!=n);
Serial.println("Larger number = ");
Serial.println(max);
}
FLOWCHART