Assignment2 July2024
Assignment2 July2024
2. If an integer requires two bytes of storage, what is the maximum value of an unsigned
integer in C?
a) 215 – 1
b) 216 – 1
c) 215
d) 216
Explanation: An unsigned integer uses all bits for the value. With 16 bits, the maximum
value is 216 - 1 (65535).
a) I and II
b) II and III
c) I, II and IV
d) All of the above are correct
#include <stdio.h>
int main() {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
printf("%d %d", a, b);
return 0;
}
a) 10 5
b) 5 10
c) 0 15
d) Compilation error
Solution: (a) 10 5
Explanation: This code swaps the values of ‘a’ and ‘b’ without using a temporary
variable.
int main() {
int sum = 3 + 6 / 2 + 6 * 2;
printf("%d", sum);
return 0;
}
#include <stdio.h>
#define SQUARE(x) x*x
int main() {
int result = SQUARE(2+3);
printf("%d", result);
return 0;
}
Problem Solving through Programming in C
Week 02 Assignment Solution
a) 25
b) 13
c) 11
d) Compilation error
Solution: (c) 11
a) stdlib.h
b) math.h
c) iostream.h
d) stdio.h
a) To terminate a loop
b) To end a program
c) To exit a function and return a value
d) To declare a variable