NPTEL Problem Solving Through Programming in C Week 3 Quiz Assignment | NPTEL Swayam Assignment Answers
Q.1: 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,",z);
printf("%d",a);
return 0;
}
Options are:
a) 120, 120
b) 120, 130
c) 130, 120
d) 130, 130
Answer is (b) 120, 130
Q.2: What will be the output of the following program:
#include<stdio.h>
int main()
{
int p=2;
int k;
int m=10;
k=!((p<2)&&(m>2));
printf("%d",k);
return 0;
}
a) 1
b) 0
c) -1
d) 2
Answer is (a) 1
Q.3: Find the output of following C code:
#include<stdio.h>
#include<math.h>
int main()
{
int a=5,b=2,c=6;
float x1,x2;
if(b*b>4*a*c)
{
x1=-b+sqrt(b*b-4*a*c)/2*a;
x2=-b-sqrt(b*b-4*a*c)/2*a;
printf("x1=%f, x2=%f",x1,x2);
}
else{
printf("Roots are imaginary");
}
return 0;
}
Options are:
a) x1=4, x2=3
b) x1=-5, x2=-4
c) x1=2.5, x2=4.2
d) Roots are imaginary
Answer is (d) Roots are imaginary
Q.4: Find the output of following code:
#include<stdio.h>
int main()
{
int p = 6 ,q = 4 ,r = 10;
if(p > q)
{
if(p > r)
printf("%d", p);
else
printf("%d", r);
}
else{
if(r>q)
printf("%d", r + q );
else
printf("%d", q);
}
return 0;
}
Options are:
a) 6
b) 4
c) 10
d) 14
Answer is (c) 10
Q.5: Which of the following statement is correct?
I The 'else' block is executed when condition inside 'if' statement is false.
II One if statement can have multiple 'else' statement.
Options are:
a) Only I
b) Only II
c) Both I and II
d) None of the above is correct
Answer is (a) Only I
Q.6: C modulo division operator '%' can be applied on:
Options are:
a) only float variables
b) only int variables
c) int and float combination
d) any data types in C
Answer is (b) only int variables
Q.7: The output of the following will be:
#include<stdio.h>
int main(){
if(0){
printf(" C programming\n");}
if(0.5){
printf("Java \n");}
if(-0.5){
printf("Python \n");}
return 0;
}
Options are:
a) C programming
b) Java
Python
c) C programming
Java
d) Compilation error
Answer is b) Java
Python
Q.8: What will be the output:
#include<stdio.h>
int main()
{
int p=2;
int k;
k=p>10?2:10;
printf("%d",k);
return 0;
}
Options are:
a) 2
b) 8
c) 10
d) 12
Answer is (c) 10
Q.9: What will be the output:
#include<stdio.h>
int main() {
int s=20;
if(s=19){
printf("Right");}
else{
printf("Wrong");}
return 0;
}
Options are:
a) Right
b) Wrong
c) 0
d) No output
Answer is (a) Right
Q.10: What will be the output of the program ?
#include<stdio.h>
int main(){
int a=2,b=3,c=5,d=8,ans;
ans-a-b+c*a/d%b;
printf("The answer will be %d", ans);
return 0;
}
Options are:
a) The answer will be 15
b) The answer will be 0
c) The answer will be 1
d) Compilation error
Answer is (b) The answer will be 0
If you are facing any queries regarding this assignment solutions, then please drop comment in comment section.
0 Comments