
[Koleksi Kode Sumber C] (8) : Menghitung luas dan keliling sebuah lingkaran
/* P-2.2 */ /* Calculate the area and circumference of a circle of specified radius */ #include <stdio.h> #define PI 3.14159 int main(void) { double radius, /* input - radius of a circle, cm */ area, /* output - area of a circle, cm^2 */ circumference; /* output - circumference of a circle, cm */ /* Get the radius. */ printf("Enter the radius in cm: "); scanf("%lf",&radius); /* Calculate the area and circumference. */ area = PI*radius*radius; circumference = 2*PI*radius; /* Display the output. */ printf("The area is %f cm^2.\n",area); printf("The circumference is %f cm.\n",circumference); return (0); }
Sumber : David R. Brooks C Programming: The Essentials for Engineers and Scientists. Springer, NY, 1999
Leave a Reply