example of scanf & printf

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

main.cpp

Committer:
yokotay
Date:
2018-06-29
Revision:
1:5dda181255b2
Parent:
0:879aa9d0247b

File content as of revision 1:5dda181255b2:

/* an example for scanf() & printf() */

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
 
int main() {
    int num;
    while(1) {
        pc.printf("Input any integer number: ");
        pc.scanf("%d", &num);
        pc.printf("\r\nnum = %d\r\n", num);
        pc.printf("num^2 = %d\r\n", num*num);
    }
}