Advertisement
rdsedmundo

palavras primas.c

Jul 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int isprimo(int a) {
  5.     if(a == 1)
  6.         return a;
  7.  
  8.     int i, count = 0;
  9.     for(i = a; i > 0; i--) {
  10.         if(a%i == 0)
  11.             count++;
  12.     }
  13.     return (count == 2) ? 1 : 0;
  14. }
  15.  
  16. int ValorC(char chr) {
  17.     if(chr >= 65 && chr <= 90) { // maiusculo
  18.         return (chr - 38);
  19.     }
  20.  
  21.     return (chr - 96);
  22. }
  23.    
  24. int main(void) {
  25.     int i, j, k;
  26.  
  27.     char Palavras[1024][21];
  28.  
  29.     for(i = 0; i < 1024; i++)
  30.         strcpy(Palavras[i], "");
  31.    
  32.     i = 0;
  33.     while(1) {
  34.         char Palaux[21];
  35.         scanf("%s", Palaux);
  36.  
  37.         if(feof(stdin))
  38.             break;
  39.  
  40.         strcpy(Palavras[i], Palaux);
  41.         i++;
  42.     }
  43.  
  44.     for(i = 0; i < 1024; i++) {
  45.         if(strcmp(Palavras[i], "") == 0)
  46.             break;
  47.  
  48.         int cSoma = 0;
  49.         for(j = 0; j < strlen(Palavras[i]); j++)
  50.             cSoma += ValorC(Palavras[i][j]);
  51.    
  52.         if(isprimo(cSoma))
  53.             printf("It is a prime word.\n");
  54.         else
  55.             printf("It is not a prime word.\n");
  56.     }
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement