6 条题解

  • 2
    @ 2023-6-20 21:05:54
    #include<bits/stdc++.h>
    using namespace std;
    double a,b;
    int main()
    {
        cin>>a;
        b=abs(a);
        cout <<fixed<<setprecision(2)<<b;
        return 0;
    }//这个用abs函数就可以做出来了
    
    • 0
      @ 2024-6-15 18:00:03
      #include <bits/stdc++.h>
      using namespace std;
      double n;
      int main()
      {
          cin >> n;
          cout << fixed << setprecision(2) << abs(n);
          return 0;
      }
      
      • 0
        @ 2023-7-28 10:34:59
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            double a;
            cin>>a;
            cout<<fixed<<setprecision(2)<<abs(a);
            return 0;
        } 
        

        我又双叒叕来发题解了!

        • 0
          @ 2023-6-22 14:20:41
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              double a;
              cin>>a;
              a = abs(a);
              printf("%.2lf",a);
              return 0;
          }
          
          • 0
            @ 2023-6-21 0:24:29

            计算浮点数的绝对值可以使用fabs()函数。该函数的原型为:

            double fabs(double x);
            
            

            其中,参数x为要计算绝对值的浮点数,返回值为x的绝对值。

            因此,在本程序中,只需要读入一个浮点数,使用fabs()函数计算它的绝对值,并使用fixedsetprecision()函数控制输出精度即可。

            解析:

            1. 导入头文件
            #include <iostream>
            #include <cmath>
            #include <iomanip>
            
            

            本程序使用了iostreamcmathiomanip三个头文件,分别用于输入输出、数学计算和精度控制。

            1. 定义变量

            本程序定义了一个变量x,表示要计算绝对值的浮点数。

            double x;
            
            1. 读入数据
              cin >> x;
              

            通过cin函数从标准输入流中读入一个浮点数x

            1. 计算并输出绝对值
            cout << fixed << setprecision(2) << fabs(x) << endl;
            
            

            使用fabs()函数计算浮点数x的绝对值,并使用fixedsetprecision()函数控制输出精度。最后将结果输出。

            完整代码: 你自己想,我就不写了

            • 0
              @ 2023-6-20 20:00:15
              #include <bits/stdc++.h>
              using namespace std;
               
              int main()
              {
              	float n;
              	cin >> n;
              	if (n >= 0)
              		printf("%.2f",n);
              	else 
              		printf("%.2f",-n);
              	return 0;
              }
              
              • 1

              信息

              ID
              160
              时间
              1000ms
              内存
              128MiB
              难度
              3
              标签
              递交数
              232
              已通过
              121
              上传者