0
Follow
0
View

How to solve the problem of #c++#?

darky123 注册会员
2023-02-27 17:14
< div class = "md_content_show e397 data - v - 3967" = "" >

hexadecimal conversion output reference is as follows:


#include 
#include 
using namespace std;

int main()
{
    int n;
    cout << "请输入一个整数:";
    cin >> n;
    cout << "十进制:" << n << endl;
    cout << "八进制:" << setw(3) << setfill('0') << oct << n << endl;
    cout << "十六进制:0x" << hex << n << endl;
    return 0;
}

cxiao007 注册会员
2023-02-27 17:14

with < br / >(1) namespace util. H

#ifndef _UTIL_H_
#define _UTIL_H_


namespace math
{
    int getNum(int n =1);
}

#endif // !_UTIL_H_

util.cpp

#include "util.h"

int math::getNum(int n)
{
    for (int k = n; k >= 1; k--)
    {
        int sum = 0;
        int t = k;
        while (t)
        {
            sum += t % 10;
            t /= 10;
        }
        if (k % sum == 0)
            return k;
    }
    return 1;
}

main.cpp

#include 
#include "util.h"
using namespace std;
using namespace math;


int main()
{
    int n;
    cout << "请输入一个正整数:";
    cin >> n;
    cout << math::getNum(n) << endl;
    return 0;
}

(2)
Octal
hex output

About the Author

Question Info

Publish Time
2023-02-27 17:14
Update Time
2023-02-27 17:14

Related Question

vs2022未能正确加载data toola包

有没有类似torch.topk()的方法,可以取出前几个最大值的下标,同时还能进行反向传播?

autojs Pro设置无障碍服务开启关闭按钮的代码哪里错了

创建一个PyTorch序列张量,不包含指定值

如何从Artifactory检索项目列表

如何在QLineEdit中设置选项“ShowTabsAndSpaces”

EF核心应用TOP内部查询

点运行点击button他会自己移动位置

ADO.NET query returning nothing even if the item available

nacos_monitor{name='subServiceCount'}