10924 - Prime Words

#include <stdio.h>
#include <string.h>
int main()
  {
  char str[50],c;
  long i,j,sum;

  while(scanf("%s",&str)!=EOF)
      {
      sum=0;
      i=strlen(str);
      for(j=0;j<i;j++)
         {
         for(c=97;c<=122;c++)
            if(str[j]==c)
             sum=sum+(c-96);

         for(c=65;c<=90;c++)
            if(str[j]==c)
              sum=sum+(c-38);
         }//End of 1st for

           long r,k;
           r=(long)sum/2;
           for(k=2;k<=r;k++)
               if(sum%k==0) break;

           if(i==1 && str[0]=='a')
                printf("It is a prime word.\n");
           else if(k==r+1)
              printf("It is a prime word.\n");
           else
              printf("It is not a prime word.\n");
      } // End of while
  } // End of main

Comments

Popular posts from this blog

371 - Ackermann Functions

Create many folder with one click