Read an integer or floating point value from the command line. It will come into
ID: 3797069 • Letter: R
Question
Read an integer or floating point value from the command line. It will come into your program as argv[1]. Remember that argv[1]'s type is a pointer to a character that begins a sequence of characters that end in a null byte. In other words, it is what is agreed upon as a string. String is not a base type within the C language. For example, $./assignment04pe03 4.3 prints out the trigonometric sine value of the number represented by argv[1]. You would do this by calling the proper functions that are found in Appendix D of your textbook. Check out the atof function. Name your program assignment.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Please run ./assignment04pe03 <floating point number>. Example assignment04pe03 4.3 ");
exit(1);
}
float f = atof(argv[1]);
printf("%f ", sinf(f));
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.