

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Today’s lab has us playing with data types.
Problem 0: Which of the following are valid variable names? Feel free to compile and check for errors.
int 4variable;
int intVariable;
int variable;
int variable 1;
int variable ;
int i 4;
Problem 1: double a = 1.0e2; double b = .01; printf(”a in scienfitic %e\n”,a); printf(”b in scienfitic %e\n”,b); printf(”a in standard %f\n”,a);
printf(”b in standard %e\n”,b);
Record the output from the above code:
Problem 2: Given: int a = 1; int b = 2; int c = 3; int result; For each expression write down what you expect to get as the solution. Then code the expression and write down what out- put of the program is using: printf(”Output %d\n”, result );
(1) result = a − 5 ∗ b/c + 1 Expected: Executed:
(2) result = a − 5 ∗ b/(c + 1) Expected: Executed:
(3) result = a − 5 ∗ (b/c) + 1 Expected: Executed:
(4) result = (a − 5) ∗ b/c + 1 Expected:
CPS 196: Introduction to C (Summer 2009) Page 1
Executed:
(5) result = a − 5 ∗ b/c + 1 Expected: Executed:
Problem 3: Execute the following code and record the result: int x = 5 / 0; Result:
Problem 4: Write a program that squares double input from the user (via scanf) and displays the result.
Problem 5: Write a program to converts a degrees in Fahrenheit (F) to Celsius (C) using the formula:
C =
Get the value of F from the user via scanf.
Problem 6: Write a program to evaluate the polynomial:
3 x^3 − 5 x^2 + 6 Get the value of x from the user via scanf.
CPS 196: Introduction to C (Summer 2009) Page 2