IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CSimple Functions : Circle Circumference & Area Calculator
<05.10>
#include <stdio.h> #include <math.h> #define PI 3.1415926 /* Computes the circumference of a circle with radius r */ /* r is defined and is > 0 */ /* PI is a constant macro representing an approximation of pi */ double find_circum(double r) { return (2.0 * PI * r); } /* Computes the area of a circle with radius r */ double find_area(double r) { return (PI * pow(r, 2)); } int main (void) { /* declarations */ double diam, area, circ, r; /* get diameter from user */ printf ("Enter a value for the diameter: "); scanf ("%lf", &diam); /* do the computations by calling the functions */ r = diam / 2; area = find_area (r); circ = find_circum (r); /* display the report on the screen */ printf ("\nA circle with a diameter of %3.1lf cm, ", diam); printf ("has an area of %5.3lf cm2\n", area); printf ("and a circumference of %4.2lf cm.\n", circ); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter a value for the diameter: 14.5 A circle with a diameter of 14.5 cm, has an area of 165.130 cm2 and a circumference of 45.55 cm.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland