UVA 10924 - Prime Words

UVA Sep 01, 2020

Problem PDF

Solution:

#include
#include
#include
#include
#include
int main()
{
int i,l,sum,n,p,j;
char c[100];
while(gets(c))
    {
    sum=0;
    l=strlen(c);
    for(i=0;i='a'&&c[i]<='z')
        {
        n=toascii(c[i])-96;
        sum=sum+n;
        }
        else
        {
        n=toascii(c[i])-38;
        sum=sum+n;
        }
    }
    //printf("%d",sum);
        p=1;
        for(j=2; j<=sqrt(sum); j++)
        {
            if(sum%j==0)
            {
                p=0;
                break;
            }
        }
        if(p==1 || sum==1)
            printf("It is a prime word.\n");

        else if(p==0)
            printf("It is not a prime word.\n");
    }
    return 0;
}

https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/10924/10924.cpp

Tags

Shipu Ahamed

CSPO® | Partly Product, Project Manager and Partly Software Engineer.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.