The arithmetic functions calculate common arithmetic functions which are not directly supported by the language.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void Display (double);
void DisplayInt (int Value);
void DisplayLong (long Value);
int main () {
DisplayInt (rand () - rand());
DisplayLong ((long)(rand () - rand()));
Display (.16 * (double)(rand() % 100) - 8.0);
DisplayInt (rand () - rand());
DisplayLong ((long)(rand () - rand()));
Display (.16 * (double)(rand() % 100) - 8.0);
DisplayInt (rand () - rand());
DisplayLong ((long)(rand () - rand()));
Display (.16 * (double)(rand() % 100) - 8.0);
return 0;
}
void DisplayInt (int Value) {
printf ("The absolute value of int %i is %i\n",
Value, abs (Value));
}
void DisplayLong (long Value) {
printf ("The absolute value of long %li is %li\n",
Value, abs (Value));
}
void Display (double Value) {
printf ("The absolute value of double %f is %f\n",
Value, fabs (Value));
printf ("The ceiling of %f is %f\n",
Value, ceil (Value));
printf ("The floor of %f is %f\n",
Value, floor (Value));
printf ("The square root of the absolute value of %f is %f\n\n",
Value, sqrt (fabs (Value)));
}
The absolute value of int -10852 is 10852 The absolute value of long -10566 is 10566 The absolute value of double -5.280000 is 5.280000 The ceiling of -5.280000 is -5.000000 The floor of -5.280000 is -6.000000 The square root of the absolute value of -5.280000 is 2.297825 The absolute value of int 11180 is 11180 The absolute value of long -8178 is 8178 The absolute value of double -7.360000 is 7.360000 The ceiling of -7.360000 is -7.000000 The floor of -7.360000 is -8.000000 The square root of the absolute value of -7.360000 is 2.712932 The absolute value of int 10987 is 10987 The absolute value of long 4387 is 4387 The absolute value of double 1.600000 is 1.600000 The ceiling of 1.600000 is 2.000000 The floor of 1.600000 is 1.000000 The square root of the absolute value of 1.600000 is 1.264911
| C++ Now | C++ Arithmetic |
| C# Now | C# Arithmetic |
| FORTRAN Now | FORTRAN Arithmetic |
| Java Now | Java Arithmetic |
| Pascal Now | Pascal Arithmetic |
| PHP Now | PHP Arithmetic |
Copyright © 1999-2007, jhyoung,
revised 9/14/2007