MSOE EE2905 / Mbed 2 deprecated Factorial_Function

Dependencies:   mbed

Fork of Factorial_Function by Sheila Ross

Revision:
0:c8831b97b76a
Child:
1:e6e33adba30e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 22 15:48:50 2017 +0000
@@ -0,0 +1,39 @@
+/*  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);
+
+            }
+        }
+    }
+}
\ No newline at end of file