Page 186 - ARM Based Microcontroller Projects Using MBED
P. 186
/******************************************************************
TIMES TABLE
===========
This program displays the times table for a given number. The user
enters a number and the program calculates and displays the times
table for this number from 1 to 12. The table is displayed for 5s.
After this time the process is repeated.
Author: Dogan Ibrahim
Date : August 2018
File : Timestable
********************************************************************/
#include "mbed.h"
Serial MyPC(USBTX, USBRX);
//
// Clear the screen
//
void clrscr()
{
char clrscr[] = {0x1B, '[', '2' , 'J',0};
MyPC.printf(clrscr);
}
//
// Home the cursor
//
void homescr()
{
char homescr[] = {0x1B, '[' , 'H' , 0};
MyPC.printf(homescr);
}
int main()
{
int Number;
while(1)
{
clrscr(); // Clear the screen
homescr(); // Home the cursor
MyPC.printf("\n\rEnter the Number: ");
MyPC.scanf("%d", &Number); // Read the number
MyPC.printf("");
MyPC.printf("\n\rTIMES TABLE FOR %d", Number); // Display heading
MyPC.printf("\n\r=================");
MyPC.printf("");
//
// Display the times table for the entered Number
//
for(int k = 1; k <=12; k++)
{
MyPC.printf("\n\r%d X %d = %d", Number, k, k*Number);
}
wait(5.0); // Wat 5 seconds
}
}
FIG. 8.32, CONT’D