Assignment4 July 2024
Assignment4 July 2024
a) x=1
b) x=0
c) Depends on compiler
d) No print statements
Solution: (d) x is initialized with 1 and the if statement compares it with 0, thus the if condition is
false and the nested if statements do not get executed. Hence, the program does not print anything.
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
4. 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
Solution: (b) Multiple conditions are tested from Left to the right.
.
Problem Solving through Programming in C
Week 04 Assignment Solution
5. 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) NPTEL
b) PROGRAMMING
c) No output
d) Compilation error as A and a are not declared as character variable
Solution: (a)
The ASCII value of ‘A’ is 65, which is lesser than the ASCII value of ‘a’ (i.e., 97). Therefore, if the
condition is true, NPTEL is printed.
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.