Monday, February 17, 2020

check if an integer is prime or not


#include <stdio.h>

int main()
{
  int n, c;

  printf("Enter a number\n");
  scanf("%d", &n);

  if (== 2)
    printf("Prime number.\n");
  else
  {
    for (= 2; c <= n - 1; c++)
    {
      if (% c == 0)
        break;
    }
    if (!= n)
      printf("Not prime.\n");
     else
       printf("Prime number.\n");
  }
  return 0;
}
Example 6 - command line arguments
#include <stdio.h>
int main(int argc, char *argv[])
{
  int c;
  printf("Number of command line arguments passed: %d\n", argc);
  for (= 0; c < argc; c++)
    printf("%d argument is %s\n", c + 1, argv[c]);
  return 0;
}
This program prints the number of arguments and their contents.

No comments:

Post a Comment