开发者

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

开发者 https://www.devze.com 2022-12-07 19:17 出处:网络
For example, if this number 188825 is passed,开发者_StackOverflow中文版 then the output will show 1,2 and 5 as a prime number.

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

精彩评论

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