67. To check if a number is prime or not Yes: Add all alternate digits No: Multiply all alternate digits
#include<stdio.h>
void
main()
{
int mul=1,add=0,r,num,i,c=0,digit=1;
printf("To check if a number is
prime or not \nYes: Add all alternate digits \nNo: Multiply all alternate
digits\n");
printf("Enter a number : ");
scanf("%d",&num);
for(i=2;i<num;i++)
{
if(num%i==0)
{
c++;
break;
}
}
if(c==0)
{
printf("Its a prime
number\n");
for(;num;num=num/10)
{
r=num%10;
if(digit%2!=0)
add=add+r;
digit++;
}
printf("%d\n",add);
}
else
{
printf("Its a non prime
number\n");
for(;num;num=num/10)
{
r=num%10;
if(digit%2!=0)
mul=mul*r;
digit++;
}
printf("%d\n",mul);
}
}
Comments
Post a Comment