当前位置:网站首页>Area of Blue Bridge Cup 2 circle

Area of Blue Bridge Cup 2 circle

2022-06-26 07:50:00 Don't hit me, it hurts!

Problem description
Radius of given circle r, Find the area of a circle .
Input format
Input contains an integer r, Represents the radius of a circle .
Output format
Output one line , Contains a real number , Round to decimal 7 position , Represents the area of a circle .

explain : In the subject , Input is an integer , But the output is a real number .

On the problem of real number output , Please be sure to see the requirements of real output , For example, it is required to keep the decimal point after this question 7 position , Your program must Strict Output 7 Decimal place , It's not good to output too many or too few decimal places , Would be considered wrong .

If there is no special explanation for the problem of real number output , Rounding is done by rounding .

The sample input
4
Sample output
50.2654825
Data scale and agreement
1 <= r <= 10000.
Tips
This problem requires high precision , Please note that π The value of should take a more accurate value . You can use constants to represent π, such as PI=3.14159265358979323, You can also use mathematical formulas to find π, such as PI=atan(1.0)*4.


Code :

#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int r;
    double s;
    cin>>r;
    double PI=3.14159265358979323;
    s=PI*r*r;
    printf("%.7lf\n",s);
    return 0;
}

The title is not difficult. , But there are some knowledge points .

Keep the decimal places :

c++ The method provided in is troublesome , With the help of c Methods in language ,

 printf("%.2f\n", a);// Retain 2 Decimal place ,%.?f ? The number at indicates the number of decimal places reserved

The header file :#include <stdio.h>

原网站

版权声明
本文为[Don't hit me, it hurts!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170609120354.html