# C++输出一个范围高的数

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/21693.html | 发布：2023-06-30 | 更新：2023-06-30 | 分类：建站教程

在C语言或者C++中数据都有范围  
unsigned int 0～4294967295  
int -2147483648～2147483647  
unsigned long 0～4294967295  
long -2147483648～2147483647  
long long：-9223372036854775808～9223372036854775807  
unsigned long long：0～18446744073709551615  
#include <iostream>  
using namespace std;  
int main()   
{  
 int c ;  
 c = 21474836471;  
 cout<<c;  
 return 0;  
}

 

此时由于超int的数据类型范围，所以输出了乱码。  
改为最大范围的unsigned long long类型就能输出

 

#include <iostream>  
using namespace std;

 

int main(void)   
{  
 unsigned long long c ;  
 c = 21474836471;  
 cout << c;  
 return 0;  
}如果连的unsigned long long类型都超过，就只能这样了

 

#include <bits/stdc++.h>  
using namespace std;  
const int N = 9999999;  
string c = "139922498948348494839893839849982938938928292";  
int a[N];

 

int main()   
{  
 for (int i = 0; i < c.length(); i++)   
 {  
 a[i] = c[i] - '0';  
 }  
 for (int i = 0; i < c.length(); i++)   
 {  
 cout << a[i];  
 }  
}

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
