Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

Program Discussion :: Basics

Home > Programs > Basics

9 / 265

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: