Saturday, March 18, 2017

URI problem 1165 solution in C | (Prime Number)

Please visit this link to find the solutions-

Link:https://codespathshala.com/uri-1165/



/

2 comments:

  1. #include
    #include
    using namespace std;

    int main()
    {
    int t, n;

    cin >> t;

    while(t--)
    {
    cin >> n;
    if( n < 10 )
    {
    if( n==2 || n==3 || n==5 || n==7)
    cout << n << " eh primo\n";
    else
    cout << n << " nao eh primo\n";
    }
    else{
    int root = sqrt(n*1.0);
    int nonPrime = 0;

    if( n%2 == 0) nonPrime = 1;
    else
    for(int i=3; i<=root; i+=2)
    {
    if(n%i == 0){
    nonPrime = 1;
    break;
    }
    }
    if( nonPrime == 0)
    cout << n << " eh primo\n";
    else
    cout << n << " nao eh primo\n";
    }
    }

    return 0;
    }

    ReplyDelete
  2. #include
    int main()
    {
    int i,n,j,x,y=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    scanf("%d",&x);
    for(j=2;j<x;j++)
    {
    if(x%j==0)
    y++;
    else
    continue;
    }
    if(y!=0)
    printf("%d nao eh primo\n",x);
    else
    printf("%d eh primo\n",x);
    x=0;
    y=0;

    }
    return 0;
    }
    reply..

    ReplyDelete