Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Factorial_Function by
main.cpp
- Committer:
- rossatmsoe
- Date:
- 2017-09-22
- Revision:
- 0:c8831b97b76a
- Child:
- 1:e6e33adba30e
File content as of revision 0:c8831b97b76a:
/* Factorial
Demonstrates the use of a for loop to compute a factorial, and use of scanf
Turn on local echo in your terminal application to see what you have typed
*/
#include "mbed.h"
Serial pc(USBTX,USBRX);
int n;
int main()
{
while(1) {
pc.printf("Enter the number (0 through 12):\n");
pc.scanf("%d",&n);
if(n<0) {
pc.printf("Error: Number must be non-negative\n");
}
else {
if(n>12) {
pc.printf("Error: Number is too large\n");
}
else {
unsigned long answer=1;
for(int k=1; k<=n; k++) {
answer*=k;
}
pc.printf("%d!=%lu\n",n,answer);
}
}
}
}
