Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you will write a C program (not a shell script) The program expects a command-li

ID: 3589249 • Letter: Y

Question

you will write a C program (not a shell script)
The program expects a command-line argument, which is a real number (double)
and prints its square root.

DETAILS:

you must use the server's gcc compiler, with all default options, plus
the -lm switch to link with the math library

remember to include math.h

all real numbers are doubles

assume a single command line argument is given, and is a non-negative real

use sscanf with "%lf" to convert that argument to a double

use the sqrt() function to find its square root

use printf with the "%lf " format for output

no other output is allowed.

Explanation / Answer

#include <stdio.h>
#include<math.h>

main(int argc, char *argv[])
{
double num;
sscanf(argv[1],"%lf ",&num);
double re = sqrt(num);
printf("%lf",re);
return 0;
}