简体   繁体   English

为什么这个 c++ 代码模板不起作用? 我有麻烦了

[英]Why doesn't this c++ code template work? I'm having trouble

#include <stdio.h>
int main()
{
    int list[10];
    int a,b,c;
    int d=1;
    int e=0;
    printf("Enter a starting number to find 10 prime numbers: ");
    scanf("%d",&a);
    printf("Enter a ending number to find 10 prime numbers: ");
    scanf("%d",&b);
    for(c=0;c<10;c++)
    {
        while(a<b)
        {
            while(d<a)
            {
                if(a%d==0)
                {
                    e=1;
                }
                d++;
            }
            a++;
        }
        if(e==0)
        {
            list[c]=a;
            printf("%d is prime.",list[c]);
        }
    }
}

The code that will add 10 prime numbers in the given range to the list arr and print them.将给定范围内的 10 个质数添加到列表 arr 并打印它们的代码。 Why doesn't it work?为什么它不起作用? Thanks.谢谢。 Please explain.请解释。

to flesh out @Craig answer充实@Craig的回答

   for(c=0;c<10;)
    {
        while(a<b)
        {
            while(d<a)
            {
                if(a%d==0)
                {
                    e=1;
                }
                d++;
            }
            a++;
        }
        if(e==0)
        {
            list[c]=a;
            printf("%d is prime.",list[c]);
            c++;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C 编程:我的代码有问题 - C programming: I'm having trouble with the code 我无法结束C中的循环 - I'm having trouble ending a loop in C 我正在阅读开源代码(C++),但不知道为什么他们这样放置枚举 - I'm reading open source code (C++) and can't figure out why they put enum this way 为什么 __declspec(dllimport) 在 Visual C++ 中不能与 memcpy() 一起使用? 我如何使它工作? - Why doesn't __declspec(dllimport) work with memcpy() in Visual C++? How do I make it work? 我正在尝试用定界符分割字符串,但是它不起作用,为什么? - I'm trying to split a string by a delimiter but it doesn't work, why? 我不知道为什么我的开发C ++ #include不起作用 - i don't know why my dev c++ #include doesn't work Aptana上的代码完成C / C ++不起作用 - Code completion C/C++ on Aptana doesn't work 请提供任何帮助,我正在尝试将此 C++ 代码转换为 C 代码,但我遇到了 fflush() function 代码的问题 - Any help please, I'm trying to convert this C++ code to C code, but I'm having problem with fflush() function 为什么这个 C++ 程序对 17 13 3 5 不起作用 - Why does this C++ program doesn't work for 17 13 3 5 makefile 遇到问题:它的行为不像我被教导的那样,我不知道该怎么做 - Having trouble with makefile: it doesn't behave the way I've been taught it should and I'm not sure what to do
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM