c语言数组赋值和计算数组和的问题

    int a = 0, b = 0, ture = 0, i = 0,j=0;
    int answer = 0,score=0;
    int Score[10] = { 0 };
        for (i = 0; i<10; i++)
        {
            a = rand() % 10;
            b = rand() % 10;
            ture = a + b;//正确答案
            printf("第%d题:%d+%d=\n",i, a, b);
            printf("请输入正确答案:");
            scanf_s("%d", &answer);
            if (answer == ture)
            {
                score = 10 - j;
                printf("答对了,这一题得分是%d", score);
                printf("\n");
            }
            else
            {
                while (answer != ture && 0 < j < 3)
                {
                    j++;
                    printf("答错了\t请再输入一次\t你还有%d次机会", 3 - j);
                    scanf_s("%d", &answer);
                }
                if (answer == ture)
                {
                    score = 10 - j;
                    printf("答对了,你的得分是%d", score);
                }
                else
                {
                    printf("答错了,你的得分是0");
                    score = 0;
                }
            }
            Score[i] = score;
        }
        int sum = 0;
        sum = sum + Score[i];
        printf("你的总成绩是%d", sum);
            return 0;
        }

img

  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/1073367
  • 这篇博客你也可以参考下:C语言使用数组和循环解决约瑟夫环问题
  • 你还可以看下c语言参考手册中的 c语言-数组
  • 除此之外, 这篇博客: c语言数组概念中的 指针和数组的关系 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 数组名同时也是改数组首元素的地址。

    dates +2 ==&dates[2]   //相同的地址
    *(dates +2) == dates[2]   //相同的值
    

    对地址进行加操作,相当于是地址增加两个元素的字节地址。*对地址进行取值操作。

i在for循环结束时为10,Score[10]导致溢出