写入数组时的访问权限冲突
#include <iostream>#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
intn, S, lc, ls = 0;
int i;
void xxx(int a[],int b[],int c[],int i) {
int k = 1, flag, ll = 1;
flag = i;
do {
a = i % 10;
flag = flag / 10;
k++;
ll++;
} while (!flag);
ll--;
for (int j = 1; j <= i; j++)
{
b = a;
}
lc = ll + ll;
for (k = 1; k <= ll; k++)
{
for (int j = 1; j <= ll; j++)
{
c += a * b;
c += a * b / 10;
c = a * b % 10;
}
}
}
void addd(int sum[], int a[], int b[], int c[]) {
for (int k = 1; sum != 0; k++)
{
ls++;
}
for (int j = 1; j <= lc; j++)
{
b = c;
}
for (int k = 1; k <= ls; k++)
{
b = sum;
}
ls = max(lc, ls) + 1;
for (int j = 1; j <= ls; j++)
{
sum += a + b;
sum = sum / 10;
sum = sum % 10;
}
}
int main() {
int a, b, c, sum;
cin >> n;
a = 1;
sum = 1;
for (i = 1; i <= n; i++)
{
xxx(a,b,c,i);
addd(sum,a,b,c);
}
if (sum == 0 && ls > 0)ls--;
for (i = ls; ls > 0; ls--)
{
cout << sum;
}
return 0;
}
执行到 a = i % 10;这条语句时发生访问权限冲突,求大神指导,脑袋想不出来啦
错误1:
xxx()函数里
do {
a = i % 10;
flag = flag / 10;
k++;
ll++;
} while (!flag); //循环条件错误,当flag 初值小于10时,是个死循环,因此,循环结束条件应该是 while(flag)
错误2:
main()函数里
int a, b, c, sum;数组没有初始化就使用。
应该写成
int a={0}, b={0}, c={0}, sum={0}; xieglt 发表于 2021-1-7 08:54
错误1:
xxx()函数里
do {
谢谢谢谢大佬
页:
[1]