@ -0,0 +1,25 @@ | |||||
#include <stdio.h> | |||||
#include <limits.h> | |||||
#include <float.h> | |||||
int main (void) { | |||||
int a = INT_MAX; | |||||
float b = FLT_MAX; | |||||
// overflow | |||||
printf("Integer overflow: %d\n", a+1); | |||||
printf("Float overflow: %f\n", b + 1.0); | |||||
a = INT_MIN; | |||||
b = -FLT_MAX; | |||||
// underflow | |||||
printf("Integer underflow: %d\n", a-1); | |||||
printf("Float underflow: %f\n", b-1.0); | |||||
return 0; | |||||
} |
@ -0,0 +1,21 @@ | |||||
#include <stdio.h> | |||||
int main (void) { | |||||
unsigned int a; | |||||
printf("Give an ASCII code value: "); | |||||
scanf("%u", &a); | |||||
if (a > 127) { | |||||
printf("Outside of ASCII range\n"); | |||||
return 1; | |||||
} else { | |||||
printf("The character is: %c\n", a); | |||||
} | |||||
return 0; | |||||
} |
@ -0,0 +1,12 @@ | |||||
#include <stdio.h> | |||||
int main (void) { | |||||
printf("Startled by the sudden sound, Sally shouted,\n"); | |||||
printf("\"By the Great Pumpkin, what was that!\"\n"); | |||||
return 0; | |||||
} |
@ -0,0 +1,17 @@ | |||||
#include <stdio.h> | |||||
int main (void) { | |||||
float a; | |||||
printf("Enter a floating-point value: "); | |||||
scanf("%f", &a); | |||||
printf("fixed-point notation: %f\n", a); | |||||
printf("exponential notation: %e\n", a); | |||||
printf("p notation: %a\n", a); | |||||
return 0; | |||||
} |
@ -0,0 +1,22 @@ | |||||
#include <stdio.h> | |||||
#include <limits.h> | |||||
int main (void) { | |||||
unsigned age; | |||||
printf("Enter your age: "); | |||||
scanf("%u", &age); | |||||
if ((unsigned int)(UINT_MAX / 3.156e7) < age) { | |||||
printf("Integer overflow\n"); | |||||
return 1; | |||||
} else { | |||||
printf("You are %u seconds old\n", (unsigned int)(age * 3.156e7)); | |||||
} | |||||
return 0; | |||||
} |
@ -0,0 +1,15 @@ | |||||
#include <stdio.h> | |||||
int main (void) { | |||||
float quarts; | |||||
printf("Enter a amount of water, in quarts: "); | |||||
scanf("%f", &quarts); | |||||
printf("Number of molecules: %e\n", quarts * 950.0 / 3.0e-23); | |||||
return 0; | |||||
} |