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
COverview of C : Area and Circumference Calculator II
<01.06>
/* The "circle" program (using files) */
#include <stdio.h> #define PI 3.1416 int main (void) { double diam, area, circ, r; FILE *in, *out; /* opening files */ in = fopen ("diameter.data", "r"); out = fopen ("report_circle.txt", "w"); /* get diameter from file */ printf ("Reading data from file... "); fscanf (in, "%lf", &diam); printf ("Value read: %lf\n\n", diam); /* do the computations */ r = diam / 2; area = PI * r * r; circ = 2 * PI * r; /* send results to report file */ fprintf (out, "%4.2lf %4.2lf\n", area, circ); printf ("Sending results to file report_circle.txt...\n\n"); /* closing files */ fclose (in); fclose (out); printf ("Program completed."); return (0); }
Hergestellt in Deutschland / Made in Germany
Reading data from file... Value read: 10.400000 Sending results to file report_circle.txt... Program completed.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland