fak.c
changeset 63 5a82f89d607e
parent 9 c3fecc82ade6
child 77 49e0babccb23
--- a/fak.c
+++ b/fak.c
@@ -6,7 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-long fak (int i)
+unsigned long fak (short i)
 {
     if (i == 0)
         return 1;
@@ -18,15 +18,20 @@
 
 int main (int argc, char **argv)
 {
-    int number;
+    short number;
 
     printf ("Enter a number: ");
-    if (scanf ("%d", &number) < 0) {
+    if (scanf ("%hd", &number) != 1) {
         printf ("READ ERROR\n");
         return EXIT_FAILURE;
     }
 
-    printf ("The faktorial of %d is %ld\n", number, fak (number));
+    if (number < 0) {
+        printf ("NUMBER FORMAT ERROR\n");
+        return EXIT_FAILURE;
+    }
+
+    printf ("The faktorial of %d is %lu\n", number, fak (number));
 
     return EXIT_SUCCESS;
 }