C++编程信奥赛一本通:1025-1026-1027-1028-2070


1025-保留12位小数的浮点数

读入一个双精度浮点数,保留12位小数,输出这个浮点数。

//爱码岛编程 
#include <iostream>
using namespace std;

int main() {
  cout.flags(ios::fixed);
  cout.precision(12);

  double a;
  cin >> a;
  cout << a;
  
  return 0;
}

1026-空格分隔输出

读入一个字符,一个整数,一个单精度浮点数,一个双精度浮点数,然后按顺序输出它们,并且要求在他们之间用一个空格分隔。输出浮点数时保留6位小数。

//爱码岛编程 
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char c;
  int i;
  float f;
  double d;

  cin >> c >> i >> f >> d;
  printf("%c %d %.6f %.6f", c, i, f, d);
  return 0;
}

1027-输出浮点数

读入一个双精度浮点数,分别按输出格式“%f”,“%f”保留5位小数,“%e”和“%g”的形式输出这个整数,每次在单独一行上输出。

//爱码岛编程 
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  double d;
  cin >> d;
  printf("%f\n%.5f\n%e\n%g", d, d, d, d);
  return 0;
}

1028-字符菱形

给定一个字符,用它构造一个对角线长5个字符,倾斜放置的菱形。

//爱码岛编程 
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char c;
  cin >> c;
  printf("  %c\n", c);
  printf(" %c%c%c\n", c, c, c);
  printf("%c%c%c%c%c\n", c, c, c, c, c);
  printf(" %c%c%c\n", c, c, c);
  printf("  %c", c);
  return 0;
}

2070-【例2.13】数字对调

输入一个三位数,要求把这个数的百位数与个位数对调,输出对调后的数。

//爱码岛编程
#include <iostream>
using namespace std;

int main() {
  int n, a, b, c;
  cin >> n;
  a = n % 10;
  b = n / 10 % 10;
  c = n / 100;
  cout << a * 100 + b * 10 + c;
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值