鱼C论坛

 找回密码
 立即注册
查看: 915|回复: 1

S1E21作业,第三道操作题不输出,求大佬们看看

[复制链接]
发表于 2021-12-26 13:55:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 BlackWhite_idea 于 2021-12-26 16:05 编辑
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int count, gride, n, i, j, sum = 0;
  5.     char answer;
  6.     _Bool result = 1;
  7.     printf("输入一个整数:");
  8.     scanf("%d", count);
  9.     int text[count][4];

  10.     for (n = 3; n <= count; n++)
  11.     {
  12.         for(i=0;i<4;i++)
  13.         {
  14.             text[n][i] = 0;
  15.         }
  16.         
  17.     }

  18.     for (n = 3; n <= count; n++)
  19.     {
  20.         gride = n * n * n;
  21.         for (i = 1; i < gride; i += 2)
  22.         {
  23.             for (j = i; j < gride; j += 2)
  24.             {
  25.                 sum += j;
  26.                 if (sum == gride)
  27.                 {
  28.                     text[n][0] = gride;
  29.                     text[n][1] = i;
  30.                     text[n][2] = i + 2;
  31.                     text[n][3] = j;

  32.                     goto liu;
  33.                 }

  34.                 if (sum > gride)
  35.                 {
  36.                     sum = 0;
  37.                     break;
  38.                 }
  39.             }
  40.         }
  41.     liu:
  42.         sum = 0;
  43.     }

  44.     for(n=3;n<=count;n++)
  45.     {
  46.         if(text[n][0]==0)
  47.         {
  48.             result = 0;
  49.             break;
  50.         }
  51.     }

  52.     if (result)
  53.     {
  54.         printf("3~%d之间所有的整数均符合尼科彻斯定理!\n\n", count);
  55.         printf("是否打印所有式子:(y/n):");
  56.         getchar();
  57.         scanf("%c", &answer);
  58.     }
  59.     else
  60.     {
  61.         printf("未找到符合定义的整数!");
  62.     }

  63.     if (answer == 'y' || answer == 'Y')
  64.     {
  65.         for (n=3;n<=count;n++)
  66.         {
  67.             if (text[n][3] - text[n][1] > 4)
  68.             {
  69.                 printf("%d^3 == %d == %d + %d + ... + %d\n", n, text[n][0], text[n][1], text[n][2], text[n][3]);
  70.             }
  71.             else
  72.             {
  73.                 printf("%d^3 == %d == %d + %d + %d\n", n, text[n][0], text[n][1], text[n][2], text[n][3]);
  74.             }
  75.         }
  76.     }
  77. }
复制代码



为什么不出输出。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-12-27 19:07:29 | 显示全部楼层
才发现原来是scanf里少了个&
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 22:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表