Cytus

本文主要讨论了一篇关于C++编程的博客内容,作者在程序中使用cout输出浮点数时遇到格式控制的问题。通过输入两个整数a和b,计算并输出表达式(1-b)*a的结果。虽然作者因不熟悉cout的使用导致了错误,但最终改用printf函数成功实现了保留两位小数的输出。博客内容涉及C++的IO流库和浮点数格式控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注:使用 cout 时的格式控制 该题由于不熟悉cout使用 wa 了还是太菜

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
typedef long long LL;
using namespace std;
int main()
{
    int a;
    double b;
    double c;
    cin >> a >> b;
    c=(1-b)*a;
    printf("%.2lf\n",c);
    //cout.setf(ios::showpoint);
   // cout.precision(2);
    //cout << c ;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值