NPTEL Problem Solving Through Programming In C Week 6 Assignment Answers
Q1. Which of the following is correct statement to access 5th element in a array arr[] of size 50?
a. arr[5]
b. arr[4]
c. arr{5}
d. arr{4}
Answer: b. arr[4]
Q2. Which statement is correct?
a. An index or subscript in array is a positive integer
b. An index or subscript in array is a positive or negative integer
c. An index or subscript in array is a real number
d. None of the above statement are correct
Answer: a. An index or subscript in array is a positive integer
Q3. What is the output of the C program?
#include<stdio.h>
int main()
{
int a[3]={10,12,14};
a[1]=20;
int i=0;
while(i<3)
{
printf("%d",a[i]);
i++;
}
return 0;
}
a. 20 12 14
b. 10 20 14
c. 10 12 20
d. Compiler error
Answer: b. 10 20 14
Q4. An integer array (An integer takes two bytes of memory) of size 15 is declared in a C program. The memory location of the first byte of the array is 2000. What will be the location of the 13th element of the array?
a. 2013
b. 2024
c. 2026
d. 2030
Answer: b. 2024
Q5. To compare two arrays, we can do it by using
a. comparison operator ‘==’ directly on arrays
b. ‘Switch case’
c. ‘for’ loop
d. ‘ternary operator’ on arrays
Answer: c. ‘for’ loop
Q6. How many ‘a’ will be printed when the following code is executed?
#include<stdio.h>
int main()
{
int i=0;
char c='a';
while(i<5)
{
i++;
switch(c)
{
case 'a':
printf("%c",c);
break;
}
printf("a\n");
return 0; }
Answer: 6
Q7. What is the output of the following C program?
#include<stdio.h>
int main()
{
int arr[2]={1,2,3,4,5};
printf("%d",arr[3]);
return 0;
}
a. 3
b. 4
c. No output
d. Compilation Error
Answer: d. Compilation Error
Q8. What will be printed after execution of the following code?
#include<stdio.h>
int main()
{
int arr[10]={1,2,3,4,5};
printf("%d",arr[5]);
return 0;
}
a. Garbage Value
b. 0
c. 5
d. 6
Answer: b. 0
Q9. What is the output of the following C program?
#include<stdio.h>
int main()
{
int i;
int arr[3]={1};
for(i=0;i<3;i++)
printf("%d",arr[i]);
return 0;
}
a. 1 followed by two garbage values
b. 1 1 1
c. 1 0 0
d. 0 0 0
Answer: c. 1 0 0
Q10. What will be the output when the following code is executed.
#include<stdio.h>
int main()
{
int a[6]={1,2,3,4,5,6};
switch(sizeof(a))
{
case 1:
case 2:
case 3:
case 4:
case 5:
printf("IIT KGP");
break;
}
printf("IIT MADRAS");return 0;
}
a. IIT KGP
b. IIT MADRAS
c. Compilation Error
d. Nothing is printed
Answer: b. IIT MADRAS
For More Updates Follow Us on Telegram
Disclaimer: These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.
Also Available:
NPTEL Programming in Java Week 6 Assignment Answers
Programming in Java Week 7 Assignment Answers
Problem Solving Through Programming in C NPTEL Assignment Answers Week 7