写2*4*8*…100为什么会出现这个

写248*…100为什么会出现这个求解答,我感觉没啥问题啊。。

img

整数最大表示到21亿(2的31次方),再大就溢出了,溢出到符号位就是负的

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/715657
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:调用快递100接口物流信息错误常见问题和解决方法
  • 除此之外, 这篇博客: 简单入门排序算法(直接插入排序,折半插入排序,希尔排序,冒泡排序,堆排序,归并排序)中的 预备知识(排序数组的创建20,100 ,500 个随机数进行排序) 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    “Struct.h”

    #pragma once
    #include<iostream>
    #include<string>
    using namespace std;
    #include<cstdlib>  //C语言标准库函数,包含随机函数rand()srand(number);
    #include<ctime>  //time函数头文件
    #define MinSize 20
    #define MinddleSize 100
    #define MaxSize 500
    
    typedef struct {
    	int key;
    	//string name; 先做保留
    }Redtype;
    
    typedef struct {
    	Redtype r[MinSize + 1];
    	int length;
    	int countMove = 0;
    	int countCompare= 0 ;
    }Sqlist1;
    
    typedef struct {
    	Redtype r[MinddleSize + 1];
    	int length;
    	int countMove = 0;
    	int countCompare = 0;
    }Sqlist2;
    
    typedef struct {
    	Redtype r[MaxSize + 1];
    	int length;
    	int countMove = 0;
    	int countCompare = 0;
    }Sqlist3;
    
    void CreateList(Sqlist1 &L) {
    	L.length = 0;
    	srand(int(time(0)));
    	for (int i = 1; i <= MinSize; i++) {
    		L.r[i].key = rand() % 100;
    		L.length++;
    	}
    }
    void CreateList(Sqlist2 &L) {
    	L.length = 0;
    	srand(int(time(0)));
    	for (int i = 1; i <= MinddleSize; i++) {
    		L.r[i].key = rand() % 100;
    		L.length++;
    	}
    }
    void CreateList(Sqlist3 &L) {
    	L.length = 0;
    	srand(int(time(0)));
    	for (int i = 1; i <= MaxSize; i++) {
    		L.r[i].key = rand() % 100;
    		L.length++;
    	}
    }
    void ShowList(Sqlist1 L) {
    	for (int i = 1; i <= L.length; i++) {
    		cout << L.r[i].key << " ";
    		if (i % 20 == 0)  //每行20个
    			cout << endl;
    	}
    	cout << "\n比较次数为:" << L.countCompare << endl;
    	cout << "移动次数为: " << L.countMove << endl;
    }
    void ShowList(Sqlist2 L) {
    	for (int i = 1; i <= L.length; i++) {
    		cout << L.r[i].key << " ";
    		if (i % 20 == 0)  //每行20个
    			cout << endl;
    	}
    	cout << "\n比较次数为:" << L.countCompare << endl;
    	cout << "移动次数为: " << L.countMove << endl;
    }
    void ShowList(Sqlist3 L) {
    	for (int i = 1; i <= L.length; i++) {
    		cout << L.r[i].key << " ";
    		if (i % 20 == 0)  //每行20个
    			cout << endl;
    	}
    	cout << "\n比较次数为:" << L.countCompare << endl;
    	cout << "移动次数为: " << L.countMove << endl;
    }
    
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^