[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Basics

Home > Programs > Basics

7 / 279

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: