Week-4-July-2023 Solution
Week-4-July-2023 Solution
Solution: (c) To test a condition and execute different code based on the result.
Solution: (c) They allow you to test multiple conditions and execute different
blocks of code based on the results.
Solution: (d) If the condition is true, the program executes the code inside the "if"
block; if the condition is false, nothing happens.
a) 2
b) 3
c) 4
d) Compiler error
Solution: (a) i++ is a post-increment operator. It assigns first and then increments the
operator by one. Therefore, i value after the assignment remains 2
7. If multiple conditions are used in a single “if” statement then the testing of those
conditions are done
a) From Right to Left
b) From Left to right
c) Randomly
d) None of the above
Solution: (b) Multiple conditions are tested from Left to the right.
8. What is the purpose of the given program? n is the input number given by the
user.
#include <stdio.h>
int main()
{
int n, x = 0, y;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0)
{
y = n % 10;
x = x - y;
n = n/10;
}
printf("Output is = %d", x);
return 0;
}
a) Sum of the digits of a number
b) The negative sum of the digits of a number
c) The reverse of a number
d) The same number is printed
Solution: (b) Negative sum of the digits of a number
Week 4 Assignment Solution
Please take a number and follow the operation step-by-step. You will be able to find the
negative sum number as output.
a) a=5, b=6,c=2;
b) a=6, b=7,c=1;
c) a=6, b=6,c=2;
d) a=5, b=7,c=1;
a) Choice is 1
b) Choice other than 1
c) Both (a) and (b)
d) Syntax error
Solution: (c)
Since the “break;” statement is not used after the print statement, it will execute the default
instruction as well.