IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
Earn Free Bitcoin
CAdvanced Programming ❯ The exit Statement
<12.03>
#include <stdio.h> #include <stdlib.h> //Function factorial with Premature Exit on Negative Data //Computes n! //n is greater than or equal to zero -- premature exit on negative data int factorial (int n) { int i, product; if (n < 0) { printf("\n***Function factorial reports "); printf("ERROR: %d! is undefined***\n", n); exit (1); } else { //Compute the product n x (n-1) x (n-2) x . . . x 2 x 1 product = 1; for (i = n; i > 1; --i) { product = product * i; } return (product); } } int main (void) { int n; printf ("Enter a number: "); scanf ("%d", &n); printf ("%d! => %d\n", n, factorial(n)); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter a number: -3 ***Function factorial reports ERROR: -3! is undefined***
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.