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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.