SUM OF INTEGERS BETWEEN 101 AND 200WHOSE INDIVIDUAL DIGIT'S SUMIS A PRIME NUMBER

SUM OF INTEGERS BETWEEN 101 AND 200WHOSE INDIVIDUAL DIGIT'S SUMIS A PRIME NUMBER 
Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int i=102, j, k;
int sum = 0, digitsum;
int prime;clrscr();

do
       j = i;digitsum = 0;
            while (j > 0)
          
    {
            digitsum = digitsum + (j % 10);
                j = j / 10;
     } 

   prime = 1;
   for (k=2; k<digitsum/2; k++)
       
      {
      if (digitsum % k == 0){ prime = 0;
       break;
     }
}

if (prime == 1)
       {
             sum = sum + i;
       }

i++;
    }

 while (i < 200); 
printf("Sum is %d", sum);
getch();

}

No comments:

Post a Comment