5 solutions

  • 0
    @ 2023-10-30 13:24:31
    # π的精度要求很高,记不到的话可以用求π的公式
    #include <stdio.h>
    #include <math.h>
    #define PI 3.14159265358979323
    int main()
    {
    	int r;
    	double s;
    	scanf("%d",&r);
    	s = pow(r,2)*PI;
    	printf("%.7lf",s);
    	return 0;
    	
    }
    
    • 0
      @ 2022-11-26 13:01:09
      #include<iomanip>
      #include<math.h>
      
      #define PI acos(-1)
      
      using namespace std;
      
      int main(){
      	int r;
      	cin >> r;
      	cout << setiosflags(ios::fixed)<<setprecision(7) << PI * r * r << endl;
      }
      
      • 0
        @ 2022-5-7 13:09:19

        #include<stdio.h> //为什么我只能上传代码啊喂 #include <iostream> //然后这个格式上传过后还变成酱紫了,淦 #include<math.h> int main() { int r; double s,pi; pi=atan(1)4; scanf("%d",&r); s=pipow(r,2); printf("%.7lf\n",s); }

        • 0
          @ 2022-4-4 17:14:16

          C++

          感谢大佬,一开始还真不知道pi怎么算

          #include <cmath>
          #include <iostream>
          using namespace std;
          int main()
          {
              double pi;
              pi = atan(1) * 4;
              int r = 0;
              cin >> r;
              double s = r * r * pi;
              printf("%.7f",s);
              cout << endl;
              return 0;
          }
          
          • 0
            @ 2022-3-7 19:27:55

            这道题难在求Π的精度问题;

            刚开始一直用Π=1-(1/3)+(1/5)....的公式计算精度,但是我写的代码直接超时,要不然就是精度不够。。。

            所以以后求Π使用第二种方法:

            通过三角函数:atan(1.0)=Π/4,结果乘4得Π!!

            #include <stdio.h>
            #include <algorithm>
            #include <math.h>
            int main() {
                int  x,y;
                double pi=atan(1)*4,k=1,q=1.0/k;
                int tmp=-1;
                scanf("%d",&x);
                double s=pi*x*x;
                printf("%.7lf\n",s);
                return 0;
            }
            
            • 1

            Information

            ID
            36
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            8
            Tags
            # Submissions
            1694
            Accepted
            325
            Uploaded By