Table of Contents
NPTEL Problem Solving Through Programming in C Assignment Solutions Week 4
Q1. The control/conditional statements used in C is/are
a. ‘if-else’ statements
b. ‘switch’ statements
c. Both (a) and (b)
d. None of these
Answer: Option C
Follow us for daily updates!
Q2. What is the other statement that can avoid multiple nested if conditions?
Answer: b. ‘switch’ statements
Q3. The loop which is executed at least one is
Answer: b. do-while
Q4. ‘switch’ statement cannot use which of the following datatype:
Answer: d. float
Q5. Which of the following is a C Conditional Operator?
Answer: a. ?:
Q6. What is the output of the following code?
#include<stdio.h>
int main()
{
int x=0;
x=3<2 ? printf("5"): printf("3");
printf("%d",x);
return 0;
}
Answer: 31
Q7. Which of the following statement is correct regarding C ‘if-else’ statement?
Answer: c. ‘else’ or ‘else if’ is optional with ‘if’ statement.
Q8. What is the output of the following code
#include<stdio.h>
int main() {
if(1 > 5)
printf("Swayam\n");
printf("C Programming");
return 0;
}
Answer: b. C Programming
Q9. What will be the value of ‘i’ after the execution of the following statements?
Assume the initial values as i = 8; j = 5; k=0.
k=(j>5)?(i<5)?i-j:j-i:k-j;
i-=(k)?(i)?(j):(i):(k);
Answer: 3
Q10. What will be the value of a, b, c after the execution of the followings?
int a = 5, b=7, c = 111;
c/= ++a * b–;
Answer: c. a=6, b=6, c=2;
Problem Solving Through C Programming Solutions Week 4
Q1.
if (n2>n1)
{
if(n1 < n3)
printf("%d is the smallest number.", n1);
else
printf("%d is the smallest number.", n3);
}
else
{
if(n2 < n3)
printf("%d is the smallest number.", n2);
else
printf("%d is the smallest number.", n3);
}
}
Q2.
fact=1;
for(int i=n;i>0;i--)
{
fact*=i;
}
printf("The Factorial of %d is : %ld",n,fact);
}
Q3.
for(int i=2;i<=N;i++)
{
if(i%2==0)
sum+=i;
}
printf("Sum = %d", sum);
}
Q4.
Last_digit =N%10;
while(N>0)
{
First_digit=N%10;
N/=10;
}
Disclaimer: These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.
Also Available:
NPTEL Problem Solving Through Programming In C Assignment 3 Answers