女青年与西西 2017-06-05 14:30 采纳率: 0%
浏览 1149

新手求教改语法错误C?

不太清楚语法哪里错了?

#include <stdio.h>
#include <string.h>

int n = 1000000;
int mark[1000001];
int N, M;
int c, i;
scanf("%d,%d", &N,&M);


int main() {
    int c;
    memset(mark, 0, sizeof(mark));
    mark[0] = 1;
    mark[1] = 1;

    for (c = 2; c * c <= n; c++) {
        if (mark[c] != 1) /*是待筛选的数*/
        {
            for (i = M; i <= n / c; M++)
            {
                mark[c * i] = 1;
            }

        }
    }

    if (mark[c] != 1)
    {
        printf("%d\n", c);
    }

    return 0;
}

Line 8: error: expected declaration specifiers or '...' before string constant
Line 8: error: expected declaration specifiers or '...' before '&' token
Line 8: error: expected declaration specifiers or '...' before '&' token
Line 8: warning: data definition has no type or storage class
Line 8: error: conflicting types for 'scanf'

  • 写回答

8条回答

  • 若雪如风 2017-06-05 14:55
    关注

    int n = 1000000;
    int mark[1000001];
    int N, M;
    int c, i;
    scanf("%d,%d", &N,&M);

    这一堆放到main函数里面

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记