Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming 1. Create a new project in VS as you did in Lab 01, name it Lab03.

ID: 3748044 • Letter: C

Question

C programming

1. Create a new project in VS as you did in Lab 01, name it Lab03.
2. As before, add the file Lab03.c and in the main() function:
a. Declare variables to store three different integers, follow the good identifier naming convention.
b. Set the values 5, 10, and 20 to each variable respectively.
c. Declare a fourth variable to store a number with decimals, like 3.45
d. Add variables 1 and 2 and store the result in variable 3
e. Divide the value of variable 3 by variable 2 and store the result in variable 4. You may not get the right result, why?
(Hint: Think about what values you can store in an int)
3. At the bottom of your program, in a comment block provide the solution to the following:
Assuming: int i = 1, j = 2, k = 3, m =4;
a. Expression 1: i += j + k; Rewrite expression 1 expanding the operator +=, that is use i = ...., instead of i +=......
b. The value stored in i after evaluating the expression is: _______ (give answer in your program file as comment)
c. Expression 2: j *= k * m + 5; Rewrite expression 2 expanding the operator *=, that is use i = ...., instead of i *=......
d. The value stored in j after evaluating the expression is: _______ (give answer in your program file as comment).

Explanation / Answer

Hi,

Ans 2-
void main()
{
int p,q,r;
p=5;
q=10;
r=20;
double g=2.22;
r=p+q;
g=r/q;

Explanation :
We could not get the actual decimal result because-
r is an integer and p and q are also integer. So when we stored sum of p and q, and integr value 15 was stored in r.
and as per the decleartion q is an integer. Now are are dividing one integer with another and storing result in double variable.
Division of 2 integers will always result in integer value.

Ans 3-
int i=1;j=2;k=3;m=4;
i=i+j+k; // Expression 1
//The value stored in i after evaluating the expression is: 6
j=j*(k*m+5); //Expression 2
//The value stored in j after evaluating the expression is:34