Prime number program in c using if else

Prime number program in c using if else

 Prime number program in c using if else:
#include <stdio.h>
int main()
{
    int i, j, flag = 0;
    printf("Enter the Number: ");
    scanf("%d", &i);
    for(j = 2; j <= i/2; ++j)
    {
        if(i%j == 0)
        {
            flag = 1;
            break;
        }
    }
    if (i == 1)
    {
      printf("1 is neither a prime nor a composite number.");
    }
    else
    {
        if (flag == 0)
          printf("%d is a prime number.", i);
        else
          printf("%d is not a prime number.", i);
    }
    return 0;

}
Output:
Enter a number: 4

4 is a not Prime Number.

See also: 


Share:

Our Services

Search This Blog

  • ()
Powered by Blogger.

TikTok Sign Up and Account Registration in detail

TikTok Sign Up and Account Registration  The steps to create an account on Tik Tok application for Android and ios. Download and introd...