Problem Solving Through Programming In C Assignment 3
Course Name: Problem Solving Through Programming In C NPTEL
Link of course: Click Here
These are answers for Problem Solving Through Programming In C Assignment 3
Q1. Find the output of the following C program
#include<stdio.h>
int main()
{
int a, z, x=10, y=12;
z=x*y++;
a=x*y;
printf(“%d, %d”, z, a);
return 0;
}
a) 120, 120
b) 120, 130
c) 130, 120
d) 130, 130
Answer: b) 120, 130
Q2. What will be the output of the following program?
#include<stdio.h>
int main()
{
int p=2;
int m=10;
int k;
k=!((p<2)&&(m>2));
printf(“n%d”, k);
return 0;
}
a) 1
b) 0
c) -1
d) 2
Answer: a) 1
These are answers for Problem Solving Through Programming In C Assignment 3
Q3. Find the output of the following C code.
a) x1=4, x2=3
b) x1=-5, x2=-4
c) x1=2.5, x2=4.2
d) Roots are imaginary
Answer: d) Roots are imaginary
Q4. Find the output of the following code.
a) 6
b) 4
c) 10
d) 14
Answer: c) 10
Q5. Which of the following statements are correct?
I. The ‘else’ block is executed when condition inside if statement is false.
II. One ‘if statement can have multiple ‘else’ statement.
a) Only I
b) Only II
c) Both I and II
d) None of the above is correct
Answer: a) Only I
These are answers for Problem Solving Through Programming In C Assignment 3
Q6. Cmodulo division operator %’ can be applied on
a) only float variables
b) only int variables
c) int and float combination
d) any data types in C
Answer: b) only int variables
Q7. The output of the following program will be
a) C programming
b) Java
Python
c) C programming
Java
d) Compilation error
Answer: b)
These are answers for Problem Solving Through Programming In C Assignment 3
Q8. What will be the output?
a) 2
b) 8
c) 10
d) 12
Answer: c) 10
Q9. What will be the output?
a) Right
b) Wrong
c) 0
d) No output
Answer: a) Right
These are answers for Problem Solving Through Programming In C Assignment 3
Q10. What will be the output of the program?
a) The answer will be 15
b) The answer will be 0
c) The answer will be 1
d) Compilation error
Answer: b) The answer will be 0
Programming Assesgment Answers
Question 1
Write a C Program to calculates the area (floating point number with two decimal places) of a Circle given it’s radius (integer value). The value of Pi is 3.14
Solution:
#include <stdio.h>
#define PI 3.14
void main()
{
int radius;
float area;
/* Enter the radius of a circle */
scanf("%d", &radius);
area = PI * radius * radius;
printf("Area of a circle = %5.2f", area);
}
These are answers for Problem Solving Through Programming In C NPTEL Assignment 3
Question 2
Write a C program to check if a given Number is zero or Positive or Negative Using if…else statement.
Solution:
#include <stdio.h>
int main()
{
double number;
scanf("%lf", &number);
if(number <= 0.0)
{
if (number == 0.0)
printf("The number is 0.");
else
printf("Negative number.");
}
else
printf("Positive number.");
}
These are answers for Problem Solving Through Programming In C NPTEL Assignment 3
Question 3
Write a C program to check whether a given number (integer) is Even or Odd.
Solution:
#include <stdio.h>
int main()
{
int number;
scanf("%d", &number);
if(number % 2 == 0)
printf("%d is even.", number);
else
printf("%d is odd.", number);
}
These are answers for Problem Solving Through Programming In C NPTEL Assignment 3
Question 4
Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.
Solution:
#include <stdio.h>
int main()
{
int n1, n2, n3;
scanf("%d %d %d", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3 )
printf("%d is the largest number.", n1);
if( n2>=n1 && n2>=n3 )
printf("%d is the largest number.", n2);
if( n3>=n1 && n3>=n2 )
printf("%d is the largest number.", n3);
}
These are answers for Problem Solving Through Programming In C NPTEL Assignment 3
All weeks of Problem Solving Through Programming In C: https://progies.in/answers/nptel/problem-solving-through-programming-in-c
More NPTEL Solution: https://progies.in/answers/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.