Problem Solving Through Programming In C Week 4
Session: JAN-APR 2023
Course Name: Problem Solving Through Programming In C
Course Link: Click Here
These are Problem Solving Through Programming In C Assignment 4 Answers
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: c) Both (a) and (b)
Q2. What is the other statement that can avoid multiple nested if conditions?
a) Functions
b) ‘switch’ statements
c) ‘if-else’ statements with ‘break’
d) Loop statements
Answer: b) ‘switch’ statements
These are Problem Solving Through Programming In C Assignment 4 Answers
Q3. The loop which is executed at least one is
a) while
b) do-while
c) for
d) none of the above
Answer: b) do-while
Q4. ‘switch’ statement cannot use which of the following datatype:
a) int
b) char
c) short
d) float
Answer: d) float
These are Problem Solving Through Programming In C Assignment 4 Answers
Q5. Which of the following is a C Conditional Operator?
a) ?:
b) : ?
c) :<
d) <:
Answer: a) ?:
Q6.

Answer: 31
These are Problem Solving Through Programming In C Assignment 4 Answers
Q7. Which of the following statement is correct regarding C ‘if-else’ statement?
a) ‘else if’ is compulsory to use with ‘if’ statement.
b) ‘else’ is compulsory to use with ‘if’ statement.
c) ‘else’ or ‘else if’ is optional with ‘if’ statement.
d) None of the above
Answer: c) ‘else’ or ‘else if’ is optional with ‘if’ statement.
Q8.

a) Swayam
b) C Programming
c) Swayam C Programming
d) It won’t print anything
Answer: b) C Programming
These are Problem Solving Through Programming In C Assignment 4 Answers
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-jj-ik-j;
i-(k)?(1)?(j):(1):(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–;
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;
Answer: c) a=6, b=6, c=2;
These are Problem Solving Through Programming In C Assignment 4 Answers
Problem Solving Through Programming In C Programming Assignment
Question 1
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.
Solution:
if((n1 < n2) && (n1 < n3))
printf("%d is the smallest number.", n1);
else if(n2 < n3)
printf("%d is the smallest number.", n2);
else
printf("%d is the smallest number.", n3);
}
Question 2
Write a program to find the factorial of a given number using while loop.
Solution:
fact = 1;
int num = n;
while(num>0) {
fact = fact * num;
num--;
}
printf("The Factorial of %d is : %ld",n,fact);
}
These are Problem Solving Through Programming In C Assignment 4 Answers
Question 3
Write a Program to find the sum of all even numbers from 1 to N where the value of N is taken as input. [For example when N is 10 then the sum is 2+4+6+8+10 = 30]
Solution:
for(int i=2;i<=N;i=i+2)
sum=sum+i;
printf("Sum = %d", sum);
}
Question 4
Write a C program to calculate the Sum of First and the Last Digit of a given Number. For example if the number is 1234 the result is 1+4 = 5.
Solution:
Last_digit = N % 10;
while(N > 0) {
First_digit = N;
N = N / 10;
}
These are Problem Solving Through Programming In C Assignment 4 Answers
More Weeks of Problem Solving Through Programming In C: Click Here
More Nptel courses: https://progiez.com/nptel
Session: JULY-DEC 2022
Course Name: Problem Solving Through Programming In C NPTEL
Link of course: Click Here
These are Problem Solving Through Programming In C Assignment 4 Answers
Q1) The loop which is executed at least once is
a) “while” loop
b) “do-while” loop
c) “for” loop
d) None of the above
Answer: b) “do-while” loop
Q2) In the C programming language negative numbers when used in if-else conditional checking, are treated as
a) TRUE
b) FALSE
c) Depends on the implementation
d) None of these
Answer: a) TRUE
Q3) Choose the correct statement to use “if-else” statement in C Language
a) “else if” is compulsory to use with “if” statement.
b) “else” is compulsory to use with “if” statement.
c) “else” or “else if” is optional with the “if” statement.
d) None of the above are correct
Answer: c) “else” or “else if” is optional with the “if” statement.
These are Problem Solving Through Programming In C Assignment 4 Answers
Q4) What is the output of the following C code?
#include
int main()
{
int a = 1;
if (a–)
printf(“True\n”);
if (++a)
printf(“False\n”);
return 0;
}
a) True
b) False
c) Both ‘True’ and ‘False’ are printed
d) Compilation error
Answer: c) Both ‘True’ and ‘False’ are printed
These are Problem Solving Through Programming In C Assignment 4 Answers
Q5) In the following example, tell which statement is correct
if(condition1== 1)) && if( (condition2==1)
printf(“Swayam”);
a) Condition 1 will be evaluated first, and condition2 will be evaluated second
b) Condition2 will be evaluated first, and condition1 will be evaluated second
c) Condition 1 will be evaluated first, condition2 will be evaluated only if the condition1 is TRUE
d) Condition2 will be evaluated first, and condition1 will be evaluated only if condition2 is TRUE
Answer: c) Condition 1 will be evaluated first, condition2 will be evaluated only if the condition1 is TRUE
Q6) Which one of the following is the correct syntax for Ternary Operator in C language?
a) condition? expression1 : expression2
b) condition : expression1 ? expression2
c) condition? expression 1 < expression2
d) condition expression1 ? expression2
Answer: a) condition? expression1 : expression2
These are Problem Solving Through Programming In C Assignment 4 Answers
Q7) The purpose of the following program fragment is to
b=s+b;
s=b-s;
b=b-s;(where s and b are two integers)
a) Transfer the content of s to b
b) Transfer the content of b to s
c) Exchange (swap) the content of s and b
d) Negate the contents of s and b
Answer: c) Exchange (swap) the content of s and b
Q8) What will be the output?
#include
int main()
{
int x=0;
x = printf(“3”);
printf(“%d”,x);
return 0;
}
a) 11
b) 33
c) 31
d) 13
Answer: c) 31
These are Problem Solving Through Programming In C Assignment 4 Answers
Q9) What will be the output?
#include <stdio.h>
int main()
{
int i=0, j=1;
printf(“\n%d i++ && ++j);
printf(“\n%d”, %d”, ij);
return 0;
}
a) 0 12
b) 1 11
c) 0 00
d) 0 11
Answer: d) 0 11
Q10) What will be the value of a, b, and c after the execution of the following
int a = 5, b = 7, c = 111;
c/= ++a* b–;
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;
Answer: c) a=6, b=6, c=2;
These are Problem Solving Through Programming In C Assignment 4 Answers
Programming Assesgment Answers
Question 1
Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.
Solution:
Code
These are Problem Solving Through Programming In C Assignment 4 Answers
Question 2
Write a program to find whether a given character is a Vowel or consonant. A character is taken as input. The character may be in Upper Case or in Lower Case.
Solution:
Code
These are Problem Solving Through Programming In C Assignment 4 Answers
Question 3
Write a C program to calculate the Sum of First and the Last Digit of a given Number.
For example if the number is 1234 the result is 1+ 4 = 5.
Solution:
Code
These are Problem Solving Through Programming In C Assignment 4 Answers
Question 4
Write a C program to find power of a number using while loops. The base number (>0) and exponent (>=0) is taken from the test cases.
Solution:
Code
These are Problem Solving Through Programming In C Assignment 4 Answers
More NPTEL Solution: https://progiez.com/nptel
* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.
More from PROGIEZ
