NPTEL Problem solving through Programming In C Assignment 4 Answers

NPTEL Problem solving through Programming In C Assignment 4 Answers 2021:- We do not claim 100% surety of answers, these answers are based on our sole knowledge, and by posting these answers we are just trying to help students, so we urge do your assignment on your own.

1.The loop which is executed at least once is

a) while 

b) do-while 

c) for 

d) None of the above

Ans:- b) do-while 

2. 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 the above

Ans:- a) TRUE

3. What is the purpose of the given program? ‘n’ is the input no 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) Sum of the digits of a number 

b) Sum of the factorial of individual digits in a number 

c) The reverse of a number 

d) The same number is printed

Ans:- d) The same number is printed

4. While(1) is used in a program to create 

a) False statement 

b) Infinite loop 

c) Terminating the loop 

d) Never executed loop

Ans:- b) Infinite loop 

5. What is the output of the following C code?

#include <stdio.h>
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’ 

d) Compilation error

Ans:- c) Both ‘True’ and ‘False’ 

6. What will be printed when the following C code is executed?

#include<stdio.h>
int main()
{
  if('A'<'a')
  printf("Swayam");
  else
  printf("C Programming");
  return 0;
}

a) Swayam 

b) C Programming 

c) No output 

d) Compilation error as A and a are not declared as character variable

Ans:- a) Swayam 

7. In the following example, tell which statement is correct?

if( (condition1=1) && (condition2)=1)) printf(“hello”);

a) Condition1 will be evaluated first, condition2 will be evaluated second 

b) Condition2 will be evaluated first, condition1 will be evaluated second 

c) Condition1 will be evaluated first, condition2 will be evaluated only if the condition1 is TRUE 

d) Condition2 will be evaluated first, condition1 will be evaluated only if condition2 is TRUE

Ans:- c) Condition1 will be evaluated first, condition2 will be evaluated only if the condition1 is TRUE 

8. The purpose of the following program fragment

b=s+b;

s = b – s;

b=b-s;

where s and b are two integers is to

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

Ans:- b) transfer the content of b to s 

9. Choose the correct output of the following C code.

#include<stdio.h>
int main()
{
  int var1=10, var2=6;
  if(varl=5)
  {
     var2++;
     }
     printf("%d %d", varl,var2++);
     return 0;
}

a) 10 6 

b) 10 8 

c) 5 7 

d) 5 8

Ans:- Watch Answer on YouTube Click Here

10. What will be the output? (& & is logical AND operation)

#include <stdio.h>
int main()
{
  int i=0, j=1;
  printf("\n%d", i++ && ++j); 
  printf("\n%d %d", i,j); 
  return 0;
}

a) 0
    1  2 

b) 1
     1  1 

c) 0
    0 0 

d) 0
     1 1

Ans:- Watch Answer on YouTube Click Here

NPTEL Problem solving through Programming In C Assignment 4 Answers:- We do not claim 100% surety of answers, these answers are based on our sole knowledge, and by posting these answers we are just trying to help students, so we urge do your assignment on your own.

JOIN US ON YOUTUBE

Also Read:-

2 thoughts on “NPTEL Problem solving through Programming In C Assignment 4 Answers”

  1. Pingback: NPTEL Cloud computing Assignment 1 Answers 2021 - UNIQUE DUNIYA

Leave a Comment