[英]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.