qfedu-basic-level/day7/d12.cpp

21 lines
419 B
C++
Raw Normal View History

2023-06-21 14:30:56 +08:00
#include <iostream>
using namespace std;
int main()
{
char human_readable[] = "BKMGT"; // 人类可读的单位: 字节、千字节、兆字节、吉字节、太字节
int n;
int i = 0;
cout << "请输入一个数:";
cin >> n;
while (n >= 1024) // 原理: 除以 1024 直到小于 1024
{
n /= 1024;
i++;
}
cout << n << human_readable[i] << endl;
return 0;
}