|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/h2sol/circle.c
/*
circle.c - get a radius from the user, find the area and circumference.
The formulas you need are as follows
circumference = 2 * pi * radius
area = pi * radius * radius
ote that pi has already been defined for you below
*/
#include <stdio.h>
int main(){
//variable declarations
float radius, circumference, area;
float pi = 3.14159;
printf("Enter the radius:> ");//use printf to ask the user for a radius
scanf("%f", &radius); //use scanf to get a decimal number "%f" from the user
circumference = 2 * pi * radius; //then calculate the circumference
area = pi * radius * radius; //then calculate the area
printf("This circle's circumference is %f\n", circumference);//print the circumference
printf("This circle's area is %f\n", area);//print the area
return 0;
}
|