Code Scrappers


Prime number C program


              #include<stdio.h>
              #include<stdlib.h>

              void main()
              {
                  int n, i;

                  int flag = 0;

                  printf("Enter any number:");

                  scanf("%d", &n);

                  for (i = 2; i <= n / 2; i++)
                  {
                        if (n % i == 0)
                        {
                            flag++;

                            break;
                        }
                 }

                 if(flag) //flag != 0
                 {
                    printf("%d is not a prime number", n);
                 }

                 else
                 {
                    printf("%d is a prime number", n);
                 }
              }
          



Output

        Enter any number:5

        5 is a prime number