Tuesday, 19 November 2013

C-Program to Find the Prime digits in a Given Number

#include<stdio.h>
#include<stdlib.h>
main ()
{
int n,i=0,j=0,d,r,a[50]={0},b[50]={0},k;
printf("Enter the number\t");
scanf("%d",&n);
if(n==0)
{
printf("0 is neither prime nor composite");
exit(0);
}
i=0;
d=n;
while(n>0)
{
r=n%10;
a[i]=r;
i++;
n=n/10;
}
for(k=0;k<i;k++)
{
for(r=2;r<i;r++)
  if(a[k]%r==0)
break;
if(a[k]==r)
{
b[j]=a[k];
j++;
}
}
printf("The prime numbers are\t");
for(i=0;i<j+1;i++)
printf("%d\t",b[i]);
}



sakoncepts.blogspot.com
output

No comments:

Post a Comment