当前位置: 首页 > news >正文

对于溢出数据的处理

方法一:取模

:求1992的n次方的末两位数字

#include<iostream>
using namespace std;
int main()
{int a=1,t=0,n;cin>>n;do{++t;a=(a*92)%100;//注意本题只能进行取模运算,因为结果数值过大必定溢出 }while(t<n);cout<<a<<endl;return 0;
}

对于这种题目,最好一开始就取模,不然在运算过程中可能就会发生数据的溢出