0% found this document useful (0 votes)
115 views

Week1 Review

The document contains 18 multiple choice questions about C programming concepts such as input/output, data types, operators, constants, variables, and mathematical expressions. The questions cover a range of fundamentals including writing and running code snippets, using macros and typecasting, performing arithmetic operations, and evaluating expressions.

Uploaded by

sonal268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Week1 Review

The document contains 18 multiple choice questions about C programming concepts such as input/output, data types, operators, constants, variables, and mathematical expressions. The questions cover a range of fundamentals including writing and running code snippets, using macros and typecasting, performing arithmetic operations, and evaluating expressions.

Uploaded by

sonal268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

WEEK 1 REVIEW QUESTIONS

1. Show the output displayed by the following program lines when the data entered are 5 and 7:

printf("Enter two integers> ");


scanf("%d%d", &m, &n);
m = m + 5;
n = 3 * n;
printf("m = %d\nn = %d\n", m, n);

Show the contents of memory before and after the execution of the snippet above.

2. Show the output displayed by the following lines if the value of exp is 11 :

printf("My name is ");


printf("Jane Doe.");
printf("\n");
printf("I live in ");
printf("Ann Arbor, MI\n");
printf("and I have %d years ", exp);
printf("of programming experience.\n");

3. How could you modify the code in problem 2 above so that “My name is Jane Doe.” and “I live in
Ann Arbor, MI” would appear on the same line without running together (i.e., with a space
between the period and the “I”)?

4. Write the #define preprocessor directive and declarations for a program that has a constant
macro for PI (3.14159) and variables radius, area, and circumf declared as double , variable
num_circ as an int , and variable circ_name as a char .

5. Write a program that stores the values 'X' and 76.1 in separate memory cells. Your program
should get the values as data items and display them again for the user when done.

6. Write a program that asks the user to enter the radius of a circle and then computes and
displays the circle’s area. Use the formula
Area = PI * Radius * Radius
where, PI is the constant macro 3.14159.
7. Convert the following mathematical formulae into C-syntax:

8. Evaluate the following expressions if x is 10.5, y is 7.2, m is 5 and n is 2.


i. x / (double)m
ii. x/m
iii. (double)(n * m)
iv. (double)(n / m) + y
v. (double)(n / m)

9. Given the constants and variable declarations


#define PI 3.14159
#define MAX_I 1000
...
double x, y;
int a, b, i;
indicate which of the following statements are valid, and find the value stored by each valid
statement. Also indicate which are invalid and why. Assume that a is 3, b is 4 and y is −1.0.
i. i = a % b;
ii. i = (989 − MAX_I) / a;
iii. i = b % a;
iv. x = PI * y;
v. i = a / −b;
vi. x = a / b;
vii. x = a % (a / b);
viii. i = b / 0;
ix. i = a % (990 − MAX_I);
x. i = (MAX_I − 990) / a;
xi. x = a / y;
xii. i = PI * a;
xiii. x = PI / y;
xiv. x = b / a;
xv. i = (MAX_I − 990) % a;
xvi. i = a % 0;
xvii. i = a % (MAX_I − 990);
xviii. x = (double) a / b;

You might also like