开发者

From a given digit of numbers, how can i print which digit is prime using C?

For example, if this number 188825 is passed,开发者_StackOverflow中文版 then the output will show 1,2 and 5 as a prime number.

I wrote this program:

#include<stdio.h>
int main()
{
int i,m,n,r;
printf("Enter number:");
scanf("\n%d",&n);


while(n>=0){

int prime = 1;
r = n%10;

for(i=2;i<r;i++)
{
m = (n%i);
if(m == 0 ){
prime = 0;
}
}
if(prime == 1){
printf("%d is a prime number\n", r);
}
n = n/10;
}
}

But when i start running it, its starts going on loop. How can i fix this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜