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: Prime number program in c
Share:

Ads

Search This Blog

  • ()
Powered by Blogger.

Strings in C With Syntax, C String Program with output

Strings in C :  Strings can be defined as the one-dimensional array of characters terminated by a null ('\0'). The difference betwee...