1/28
For the first Comp Sci C quiz
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the two types of division mentioned in the notes?
Integer division and floating-point division.
How can you force the computer to perform real number division?
By using a double in the calculation, such as prepending 1.0 to the numerator.
What is the formula for converting Celsius to Fahrenheit?
F = (9/5 * C) + 32.
What is the purpose of the ceiling function in calculations?
To round up to the nearest integer.
What is the significance of the expression 'grade = ((double) x)/y'?
It casts x to a double to ensure real number division.
How do you convert a row and column to a single number?
Row = Loc / 7 and Column = Loc % 7.
What is the range of values that an int can store in C?
Between -2,147,483,648 and 2,147,483,647 (2³¹ -1 and 2^-31)
What is the purpose of the 'rand()' function in C?
To generate a random integer between 0 and 32,767. (2^15 - 1)
What are some common math functions in C?
sin(x), cos(x), tan(x), exp(x), log(x), pow(b, e), abs(x), fabs(x).
hypot(x,y), log10(x)
What is the correct way to read an integer input in C?
Using scanf("%d", &variable);.
What is the different types of variable types?
Int, String, Char, and Double(there are more, like float)
What does the expression 'int res = (int) (X + 0.5);' achieve?
It rounds the value of X to the nearest integer.
What is the relationship between degrees and radians?
180 degrees equals π radians.
How do you calculate the maximum spend based on guests and steak?
(x +y)- 1 / y
What is the output of the expression '2 + 3 * 4'?
14, due to the order of operations.
What is the purpose of escape sequences in printf statements?
To format the output, such as using '\n' for a newline.
What is the formula for the cosine law?
c² = a² + b² - 2ab * cos(C).
What is the significance of using parentheses in expressions?
They determine the order of operations.
What is the output of the expression '24/(1 + 2%3 + 4/5 +6+ 31%8)'?
The output is 1
How do you declare a variable in C?
By specifying the type followed by the variable name, e.g., 'int miles;'.
What is the output of 'printf("%d", 5);'?
It prints the integer 5.
What does the expression 'double = 1.0 + x' achieve?
It ensures that the addition is performed as a floating-point operation.
What is the escape sequence for doublequote?
\”
For the escape sequence ‘\\’, how many times does it print a backslash? Also does it work with odd backslash amounts’\\\\\’?
It prints a single backslash. However, if there is an odd number of backslashes, it won’t print anything at all(error occurs)
What are the other percent codes?
%lf for double, %c for char, %s for string, and %f for float
Why is & important and should never be forgotten?
It means address of, and it is needed every time you scan for a variable, in order to access the location of said variable to transmit what the user put in into the variable itself.
What is the constant of PI in math?
M_PI
How do you set up the #include for math and for studio?
#include <stdio.h> and #include <math.h>
How to convert from Fahrenheit to Celsius?
C = 5/9( F - 32)