c++ log()函数报错
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/07/30 14:06:40
c++ log()函数报错
#include
#include
#include
#include
int main(){
freopen("1.txt","w",stdout);
srand(time(NULL));
int cas=rand()%100+1;
int k;
while (cas--){
k=rand()%16000000+1;
int ex=rand()%('z'-'a')+1;
int n=(int)(log(k)/log(ex));//此处改为log(16000000)/log(ex)就不会报错
printf("%d %d\n",rand()%(n/5)+1,ex+1);
for (int i=0;i
#include
#include
#include
#include
int main(){
freopen("1.txt","w",stdout);
srand(time(NULL));
int cas=rand()%100+1;
int k;
while (cas--){
k=rand()%16000000+1;
int ex=rand()%('z'-'a')+1;
int n=(int)(log(k)/log(ex));//此处改为log(16000000)/log(ex)就不会报错
printf("%d %d\n",rand()%(n/5)+1,ex+1);
for (int i=0;i
![c++ log()函数报错](/uploads/image/z/2049167-47-7.jpg?t=c%2B%2B+log%28%29%E5%87%BD%E6%95%B0%E6%8A%A5%E9%94%99)
报错的不在int n=(int)(log(k)/log(ex));,而在printf("%d %d\n",rand()%(n/5)+1,ex+1);!当n小于5时n/5=0,%(n/5)就是%0,被0除了,所以报错.