Command Line Program to Check if a Number is Prime or Not

C Programming Language / Command Line Arguments

581

Program:

#include <stdio.h>

int main(int argc, char *argv[])

{

             int n, i, flag = 0;

             n = atol(argv[1]);

            for(i=2; i<=n/2; ++i)

   {

            if(n%i==0)

      {

            flag=1;

            break;

      }

   }

   if (flag==0)
            printf("%d is a prime number.",n);
   else
            printf("%d is not a prime number.",n);
   return 0;

}

Output:

13

13 is a prime number.

Explanation:

Nope

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.