Take FREE!! Online AMCAT Mock Test to Crack Wipro NLTH, Capgemini, etc.
Get Off-Campus Placement Jobs Info !!!
Practice Given Here Wipro NLTH Practice Q&A

Program Discussion :: Basics

Home > Programs > Basics

9 / 259

Write a C program which will check whether a given number N is prime or not.

If the number N is prime, then find its square root and print that value to stdout as floating point number with exactly 2 decimal precision.

If the given number N is not prime, then print the value 0.00 to stdout.

The given number N will be a positive non Zero integer and it will be passed to the program using the first command line parameter. Other than the floating point result, no other information should be printed to stdout.

Answer:

#include 
#include 
#include 

int main(int argc, char * argv[])
{
  int n, i, flag = 0;
  double x;

  if (argc == 1 || argc > 2)
  {
    printf("Enter String \r\n");
    exit(0);
  }

    n = atoi(argv[1]);
    x = n;
    for(i=2; i

Asked In :: TCS

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: