menu Secto白帽博客-专注于技术研究
C/C++基础算法练习-求P的值
1062 浏览 | 2020-03-15 | 分类:C/C++,程序设计 | 标签:C/C++,程序设计,C,算法,C++,题解

当输入S,求相应的P值,并保留两位小数。

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int s;
    double p;//p为小数
    if(s<=-50)
        p=2*s-(0.75*s-12)/2; 
    else 
        if(s<=50)
            p=3*s-(0.4667*s+2.6667)/3;
        else
            p=4*s-(0.15*s+9)/4;
    printf("%.2f",p);//保留两位小数输出
    return 0;
} 

By:海螺HL
Time:2020/3/15

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

发表评论

email
web

全部评论 (共 2 条评论)

    No Name
    2020-03-15 21:16
    我jio得有<iostream>这个头文件,就没必要再整个输入输出流<cstdio>了吧,<iostream>有cin和cout。有个取余函数是 setprecision,需要头文件<iomanip>。还有一点就是:if语句的格式有点难受啊,下次可否加上{}?这样可能更容易看。
      海螺HL
      2020-03-15 21:19
      @No Name感谢您提出的建议!
Emoji

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: file_get_contents(): Failed to enable crypto in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: file_get_contents(https://...@1.0.2/assets/json/owo.json): failed to open stream: operation failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: array_keys() expects parameter 1 to be array, null given in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 48

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 49

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: file_get_contents(): Failed to enable crypto in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: file_get_contents(https://...@1.0.2/assets/json/owo.json): failed to open stream: operation failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: array_keys() expects parameter 1 to be array, null given in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 89

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 90