Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#CPP#7591 Back

Fractional Data Types and Constants

Source Code

		 

Click to open popup

Run Output

Give Radius =2.5
Area would be : 19.6349
Circumference would be : 15.708

Code Understanding

This program calculates the area and circumference of a circle when the radius is given by the user.
• #include allows input and output commands.
• const float PI = 3.14159; defines a constant value for π (pi).
• float, double, and long double are data types used for decimal numbers with different precisions.
• cin >> radius; takes the radius from the user.
• area = PI * radius * radius; uses the formula π × r² to find the area.
• circum = 2 * PI * radius; uses the formula 2 × π × r to find the circumference.
• cout statements display the results on the screen.
• return 0; ends the program.