Lab 3 Source Code

You may cut-and-paste the following into your lab.

lab-3-1-.c

/* Your name */
/* ET2560 */
/* Unit 3 Task 1 */

#include <stdio.h>
#define PI 3.14159

/* This program accepts the radius of a circle, calculates the area, and outputs the radius and the area. */

int main(void) {
    /* Declare variables */
    double radius; /* Stores radius entered by the user */
    double area; /* Stores area after the calculation */

    /* Get radius from user */
    printf("Enter the radius of the circle: ");
    scanf("%lf", &radius);

    /* Calculate area as PI times r-squared */
    area = PI * radius * radius;

    /* Output the area */
    printf("The area of a circle with radius %f is %f\n", radius, area);
    return(0);
}