logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/cs256su21code/may25/radius.c

#include <stdio.h>

int main(){


    int radius; //the radius is the distance from the center to the edge of a circle


    printf("Enter the radius: ");
    scanf("%d", &radius); 
    /*
      getting the value of radius from the user. since we are working with integers, it is 
      necessary to use the & in front of the radius variable so that we can actually assign 
      that value we input into  the variable radius.
    */

    double area = 3.14159*(radius * radius); 
    /*
      calculating the area of a circle, since we are working with decimal values, we need to 
      declare "area" with a datatype that actually can handle decimals. double is one of these datatypes.
    */

    //if we left area as an integer, it would get rid of everything after the decimal point, and we'd have the wrong answer

    printf("The area of this circle is %f\n", area); 
    //printing the area of the circle, since "area" is a double, we use "%f" as our format string so we can print decimals.

    return 0;

}