Problem Solving Through Programming In C Week 3

Session: JULY-DEC 2023

Course Name: Problem Solving Through Programming In C

Course Link: Click Here

These are Problem Solving Through Programming In C Assignment 3 Answers


Q1. Which of the following statement is correct?
a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression
b) Operator associativity determines which operator is performed first in an expression with more than one operator with different associativity. Precedence is used when two operators of same precedence appear in an expression
c) Operator precedence and associativity are same.
d) None of the above

Answer: a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression


Q2. Find the output of the following C code
a) 67
b) -36
c) 66
d) -37

Answer: a) 67


Q3. What 1s the output of the following C code?
a) 0
b) 3
c) 4
d) Compilation error

Answer: c) 4


These are Problem Solving Through Programming In C Assignment 3 Answers


Q4. Find the output of the following C code
a) IITKGP
b) IITD and IITM
c) IITKGP and IITM
d) IITM

Answer: a) IITKGP


Q5. What will be the output?
a) Condition is true
b) Condition is false
c) Error
d) No output possible

Answer: a) Condition is true


Q6. What is the output of the following program?
a) Programming on C 0
b) NPTEL 0
c) NPTEL 3
d) Compilation error

Answer: b) NPTEL 0


These are Problem Solving Through Programming In C Assignment 3 Answers


Q7. What is the output of the C program given below
a) true
b) false
c) Compiler dependent
d) Compiler error

Answer: b) false


Q8. What will be the output?
a) 0
b) 1
c) 10
d) 30

Answer: b) 1


Q9. What will be the output?
a) TRUE
b) FALSE
c) Syntax Error
d) Compilation Error

Answer: b) FALSE


These are Problem Solving Through Programming In C Assignment 3 Answers


Q10. What is the output of the following C code?
a) 10
b) 11
c) 20
d) Compiler error

Answer: b) 11


Assignment

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:

    area = PI * radius * radius;

Question 2
Write a C program to check if a given Number is zero or Positive or Negative Using if…else statement.

Solution:

if(number <= 0.0)
    {
        if (number == 0.0)
            printf("The number is 0.");
        else
            printf("Negative number.");
    }
    else
        printf("Positive number.");
}

Question 3
Write a C program to check whether a given number (integer) is Even or Odd.

Solution:

if(number % 2 == 0)
    	printf("%d is even.", number);
    else
    	printf("%d is odd.", number);
}

Question 4
Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.

Solution:

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 Problem Solving Through Programming In C Assignment 3 Answers

More Weeks of Problem Solving Through Programming In C: Click here

More Nptel Courses: Click here


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 3 Answers


Q1. What should be the value of ‘b’ such that the output of the program will be 20?
a) 1
b) 2
c) 3
d) 4

Answer: b) 2


Q2. Find the output of the following C code
a) IITKGP
b) IITD and IITM
c) IITKGP and IITM
d) IITM

Answer: a) IITKGP


These are Problem Solving Through Programming In C Assignment 3 Answers


Q3. What is the output of the following program?
a) Programming on C 0
b) NPTEL 0
c) NPTEL 3
d) Compilation error

Answer: b) NPTEL 0


Q4. Find the output of the following C code
a) -42
b) 24
c) 15
d) -34

Answer: c) 15


These are Problem Solving Through Programming In C Assignment 3 Answers


Q5. Which of the following statement is correct?
a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression
b) Operator associativity determines which operator is performed first in an expression with more than one operator with different associativity. Precedence is used when two operators of same precedence appear in an expression
c) Operator precedence and associativity are same.
d) None of the above

Answer: a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence. Associativity is used when two operators of same precedence appear in an expression


Q6. What is the output of the C program given below?
a) true
b) false
c) Compiler dependent
d) Compiler error

Answer: b) false


These are Problem Solving Through Programming In C Assignment 3 Answers


Q7. What is the output of the following program?
a) Value of c and d are 1 and 3 respectively
b) Value of c and d are 1 and 3.333333 respectively
c) Value of c and d are 1.000000 and 3.000000 respectively
d) Value of c and d are 1 and 3.000000 respectively

Answer: d) Value of c and d are 1 and 3.000000 respectively


Q8. What will be the output?
a) TRUE
b) FALSE
c) Syntax Error
d) Compilation Error

Answer: b) FALSE


These are Problem Solving Through Programming In C Assignment 3 Answers


Q9. What will be the output?
a) 0
b) 1
c) 7
d) Compilation error

Answer: a) 0


Q10. The precedence of arithmetic operators is (from highest to lowest)
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /

Answer: a) %, *, /, +, –


These are Problem Solving Through Programming In C Assignment 3 Answers


Problem Solving Through Programming In C Programming Assignment

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:

area = PI * radius * radius;
printf("Area of a circle = %5.2f", area);
}

Question 2

Write a C program to check if a given Number is zero or Positive or Negative Using if…else statement.

Solution:

if (number <= 0.0)
    {
        if (number == 0.0)
            printf("The number is 0.");
        else
            printf("Negative number.");
    }
    else
        printf("Positive number.");
}

These are Problem Solving Through Programming In C Assignment 3 Answers


Question 3

Write a C program to check whether a given number (integer) is Even or Odd.

Solution:

if(number % 2 == 0)
        printf("%d is even.", number);
    else
        printf("%d is odd.", number);
}

Question 4

Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.

Solution:

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 Problem Solving Through Programming In C Assignment 3 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 3 Answers


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 Problem Solving Through Programming In C Assignment 3 Answers


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 Problem Solving Through Programming In C Assignment 3 Answers


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 Problem Solving Through Programming In C Assignment 3 Answers


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 Problem Solving Through Programming In C Assignment 3 Answers


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:

Code

These are Problem Solving Through Programming In C Assignment 3 Answers


Question 2

Write a C program to check if a given Number is zero or Positive or Negative Using if…else statement.

Solution:

Code

These are Problem Solving Through Programming In C Assignment 3 Answers


Question 3

Write a C program to check whether a given number (integer) is Even or Odd.

Solution:

Code

These are Problem Solving Through Programming In C Assignment 3 Answers


Question 4

Write a C Program to find the Largest Number (integer) among Three Numbers (integers) using IF and Logical && operator.

Solution:

Code

These are Problem Solving Through Programming In C Assignment 3 Answers

More NPTEL Solution: https://progiez.com/nptel



These are Problem Solving Through Programming In C Assignment 3 Answers
The content uploaded on this website is for reference purposes only. Please do it yourself first.