8 条题解

  • 2
    @ 2023-8-9 19:42:26

    这道题要注意是单精度浮点数,应使用float (PS:最后有彩蛋科普哟🎉️)

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        float a;
        cin >> a;
        cout << fixed << setprecision(3) << a;
        //使用setprecision保留3位小数
        return 0;
    }
    

    彩蛋:

    科普一下,浮点数分为三类:

    1.单精度浮点数(float)占4字节

    2.双精度浮点数(double)占8字节

    3.高双精度浮点数(long double)占8字节

    已AC,食用代码记得点赞哟🎉️

    • 1
      @ 2023-7-1 21:31:24
      #include <iostream>
      #include <cstdio>
      using namespace std;
      int main()
      {
          double q;
          scanf("%lf",&q);
          printf("%.3lf",q);
          return 0;
      }
      
      • 1
        @ 2023-5-28 15:37:21
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            float a;
            cin >> a;
            cout << fixed << setprecision(3) << a;
            return 0;
        }
        
        • 1
          @ 2023-5-20 21:17:01

          这道题的主要考点是把一个高精度的浮点数保留某几位,而且不是约等于,这就需要运用输出上的变动,在%f中间加.n可以为任何数,但在这道题里,题目已经规定了需要保留3位小数,所以这时n==3。

          下面是代码码

          #include<bits/stdc++.h>
          int main(){
          float a;
          scanf("%f",&a);
          printf("%.3f",a);
          return 0;
          }
          
          • 0
            @ 2024-4-7 19:20:35
            解析

            这道题实际上很简单,只需要将浮点数输入,再保留三位小数就行了


            #include <bits/stdc++.h>
            using namespace std;
            float a;
            int main()
            {
                scanf("%f",&a);
                printf("%.3f",a);
                return 0;
            }
            
            • 0
              @ 2023-8-5 11:29:55
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  float a;
                  cin>>a;
                  cout<<fixed<<setprecision(3)<<a<<endl;
                  return 0;
              }
              

              🔶注意是单精度浮点数,而且要保留3位小数

              • 0
                @ 2023-5-20 22:41:39

                #include<iostream> #include<iomanip> using namespace std; int main() { float a; cin>>a; cout<<fixed<<setprecision(3)<<a<<endl; return 0; }

                • -1
                  @ 2023-5-21 0:57:15
                  #include<bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                  	float a;
                      cin >> a;
                      cout << fixed << setprecision(3) << a;
                  	return 0;
                  }
                  
                  • 1

                  信息

                  ID
                  90
                  时间
                  1000ms
                  内存
                  128MiB
                  难度
                  1
                  标签
                  递交数
                  285
                  已通过
                  201
                  上传者