Prime or Not

Another easy understandable tut is in this link: http://zakilive.com/2017/05/12/check-the-number-is-prime-or-not-in-c-easy-and-details-explanation/
Code:

#include<stdio.h>
int main()
{
    int i,flag,N;
    flag=0;
    printf("eNter number to check prime: ");
    scanf("%d",&N);
    if
        (N==1)
        flag=1;
    else
{

    for(i=2;i<=N;i++)
    {
        if(N%i==0)
            flag=1;
        break;
    }
}
if(flag==0)
    printf("It's prime");
else
    printf("It's not prime");

    return 0;
}
#include<stdio.h>
int main()
{
    int i,flag,N;
    flag=0;
    printf("eNter number to check prime: ");
    scanf("%d",&N);
    if
        (N==1)
        flag=1;
    else
{

    for(i=2;i<=N;i++)
    {
        if(N%i==0)
            flag=1;
        break;
    }
}
if(flag==0)
    printf("It's prime");
else
    printf("It's not prime");

    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.