Created
January 16, 2020 02:17
-
-
Save dulimarta/eb401ec8517f7711a64c98d1542adc5b to your computer and use it in GitHub Desktop.
CS452 Sample - Error checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Be sure to link this program with the math library (-lm) | |
#include <stdio.h> | |
#include <math.h> | |
#include <errno.h> | |
int main() { | |
double x, z; | |
printf ("Enter a number: "); | |
scanf ("%lf", &x); | |
z = sqrt(x); | |
if (errno != 0) | |
perror("Bad result"); | |
else { | |
perror("Normal operation"); | |
printf ("Result is %.2f\n", z); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment