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.

C Data Types and Types of data types in C

Data types specify the type of data that a variable can store. All C compilers support Five fundamental data types, they are an integer(int...