1. What happens in C when we try to take the square root of a negative number? t
ID: 3748639 • Letter: 1
Question
1. What happens in C when we try to take the square root of a negative number? t = sqrt( -55 );
2. What happens if you have the C statement from the previous question and then have the statements double a = t + 0.5; printf( "%lf. ", a );
3. Explain what happens in C when we try to raise a number to a negative power, such as r = pow( 2, -4 );
4. What is the rational for creating symbolic constants for E and PI instead of just making them C variables, such as double PI = 3.1417; double E = 2.7182818284;
5. Variable names in C, called identifiers, generally use the underscore character _ to mashtogether words to make useful names. For example: doube city_sales_tax = 0.08; int days_in_year_2018 = 365; char superman_letter = 's'; char *mothers_maden_name = "Smith"; Another way to do this is to omit the underscore but to capitalize the first letter of each word in the identifier, except for the first word. This is called camel case, and it looks like this: doube citySalesTax = 0.08; int daysInYear2018 = 365; char supermanLetter = 's'; char *mothers_maden_name = "Smith"; In general, I don't care which you use in your programs, BUT you need to consistently use one or the other in your code, and avoid mixing the two in the same program. Which one makes the most sense to you, and why?
6.Echo printing insures the computer is working correctly. Discuss your thoughts on this statement.
7.How can you tell what information is going in to a function and what information is coming out of a function?
Explanation / Answer
1. The output will be some garbage number.
#include <stdio.h>
#include <math.h>
int main(void) {
int t = sqrt(-51);
printf("%d",t);
return 0;
}
Output:
-2147483648
2. It will add 0.5 to the garbage number
#include <stdio.h>
#include <math.h>
int main(void) {
int t = sqrt(-51);
double a = t + 0.5;
printf( "%lf. ", a );
return 0;
}
Output:
-2147483647.500000.
3. Ouput is the correct answer.
#include <stdio.h>
#include <math.h>
int main(void) {
double r = pow( 2, -4 );
printf( "%.5f", r );
return 0;
}
Output:
0.06250
4.
# define PI 3.1417
#define E 2.7182818284
5.
variables with an _ underscore is more visible and clear.
6.
Echo printing is used to get the messages on the computer screen when a process or a program is running. The blank screen can doubt a user that the process is not running or computer is hanged.
7.
Example
int function1(double x,double y);
the return value or output from the function is int .
the input to the function or parameters are double x and double y.
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.