西北农林科技大学OJ (C++) 进制转换(考察带默认参数的函数)

Description

输入一个正整数n,要求设计一个带默认参数的函数Print(int n, int base=10, bool bUpper=false),分别实现其对应10进制、8进制和16进制大小写的输出。

Input

正整数n

Output

n对应的10进制数、8进制数和大小写16进制数。

**************************************************************************************************************

Sample Input 1 

15

Sample Output 1

Dec: 15
Oct: 17
Hex: f
Hex: F

代码实现

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

void Print(int n,int base = 10,bool bUpper = false)
{
    cout<< "Dec: " << n << endl;
    cout<< "Oct: " << oct << n << endl;
    cout<< "Hex: " << hex << n << endl;
    cout<< "Hex: " << uppercase << hex << n << endl;
}

int main ()
{
    int n;
    cin >> n;
    Print(n);
    return 0;
}

初学者乍到,有问题请多多指教!!!!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值