Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Created January 16, 2020 02:17
Show Gist options
  • Save dulimarta/eb401ec8517f7711a64c98d1542adc5b to your computer and use it in GitHub Desktop.
Save dulimarta/eb401ec8517f7711a64c98d1542adc5b to your computer and use it in GitHub Desktop.
CS452 Sample - Error checking
// 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