Problem Solving Through Programming In C Nptel Week 6 Assignment Answers
Are you looking for the Problem Solving Through Programming In C Week 6 Answers 2024? You’ve come to the right place! This resource offers comprehensive solutions to the Week 6 assignment questions, focusing on fundamental concepts in C programming.
Course Link: Click Here
Table of Contents
Problem Solving Through Programming In C Week 6 Answers (July-Dec 2024)
Q1.What is the right way to initialise an array in C?
a) int arr{}={1,2,5,6,9}
b) int arr[5]={1,2,5,6,9}
c) int arr{5}={1,2,5,6,9}
d) int arr()={1,2,5,6,9}
Answer: b) int arr[5]={1,2,5,6,9}
Q2An integer array of dimension 10 is declared in a C program. The memory location of the first byte of the array is 1000. What will be the location of the 8th element of the array? (Assume integer takes 4 bytes of memory and the element stored at 1000 is identified as 1st element)
a) 1028
b) 1032
c) 1024
d) 1036
Answer: a) 1028
For answers or latest updates join our telegram channel: Click here to join
Q3.‘What will be the output after execution of the program?
a) 1
b) 2
c) 3
d) 4
Answer: a) 1
Q4.Which of the statements is correct?
a) An array contains more than one element
b) All elements of array have to be of same data type
c) The size of array has to be declared upfront
d) All of the above
Answer : d) All of the above
For answers or latest updates join our telegram channel: Click here to join
Q5.To compare two arrays, we can use
a) Comparison operator ‘==’ directly on arrays
b) Use ‘switch case’
c) Using ‘for’ loop
d) Using ternary operator on arrays
Answer: c) Using ‘for’ loop
Q6.Find the output of the following C program
a) 5,4
b) 5,5
c) 4,4
d) 3,4
Answer: c) 4,4
For answers or latest updates join our telegram channel: Click here to join
These are Problem Solving Through Programming In C Week 6 Answers
Q7.‘What will be the output?
a) i=5, j=5, k=2
b) i=6, j=5, k=3
c) i=6, j=4, k=2
d) i=5, j=4, k=2
Answer: a) i=5, j=5, k=2
Q8.Array elements are stored in memory in the following order
a) Contiguous
b) Random
c) Both contagious and random
d) None
Answer: a) Contiguous
For answers or latest updates join our telegram channel: Click here to join
Q9. ‘What is the output of the below C program?
Answer: 15
Q10.How many ‘a’ will be printed when the following code is executed?
Answer: b) 6
For answers or latest updates join our telegram channel: Click here to join
These are Problem Solving Through Programming In C Week 6 Answers
All weeks of Problem Solving Through Programming in C : Click Here
More Nptel Courses: https://progiez.com/nptel-assignment-answers
Problem Solving Through Programming In C Week 6 Answers (JULY-DEC 2023)
Course Name: Problem Solving Through Programming In C
Course Link: Click Here
These are Problem Solving Through Programming In C Assignment 6 Answers
Q1. What is an array in C?
a) A collection of similar data elements with the same data type.
b) A built-in function that performs mathematical calculations.
c) A keyword used for declaring variables.
d) A data type used to store characters only.
Answer: a) A collection of similar data elements with the same data type.
Q2. What is the index of the first element in an array?
a) 0
b) 1
c) -1
d) The index can vary depending on the array size.
Answer: a) 0
Q3. Which loop is commonly used to iterate through all elements of an array in C?
a) for loop
b) while loop
c) do-while loop
d) switch loop
Answer: a) for loop
These are Problem Solving Through Programming In C Assignment 6 Answers
Q4. An integer array of 15 elements 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? Assume int takes 2 bytes of memory.
a) 2013
b) 2024
c) 2026
d) 2030
Answer: b) 2024
Q5. How can you find the sum of all elements in a 1D array “arr” with 5 elements using loop in C?
a) sum= arr[0] + arr[1] + arr[2] + arr[3] + arr[4];
b) sum = arr[5];
c) for (int i = 0; i <= 5; i++) { sum += arr[i]; }
d) for (int i = 0; i < 5; i++) { sum += arr[i]; }
Answer: d) for (int i = 0; i < 5; i++) { sum += arr[i]; }
Q6. What is the output of the following code?
a) 1 3 5
b) 1 2 3 4 5
c) 1 2 3
d) 1 4
Answer: a) 1 3 5
These are Problem Solving Through Programming In C Assignment 6 Answers
Q7. What will be the output?
a) i=5, j=5, k=2
b) i=6, j=5, k=3
c) i=6, j=4, k=2
d) i=5, j=4, k=2
Answer: a) i=5, j=5, k=2
Q8. What will be the output after execution of the program?
a) 1
b) 2
c) 3
d) 4
Answer: d) 4
Q9. What will be the output?
Answer: 8
These are Problem Solving Through Programming In C Assignment 6 Answers
Q10. Find the output of the following C program
a) 5, 4
b) 5, 5
c) 4, 4
d) 3, 4
Answer: c) 4, 4
Assignment
Question 1
Write a C Program to find Largest Element of an Integer Array.
Here the number of elements in the array ‘n’ and the elements of the array is read from the test data.
Use the printf statement given below to print the largest element.
printf(“Largest element = %d”, largest);
Solution:
largest = arr[0];
for(i = 1; i < n; ++i)
{
if(largest < arr[i])
largest = arr[i];
}
printf("Largest element = %d", largest);
return 0;
}
Question 2
Write a C Program to print the array elements in reverse order (Not reverse sorted order. Just the last element will become first element, second last element will become second element and so on)
Here the size of the array, ‘n’ and the array elements is accepted from the test case data. The last part i.e. printing the array is also written.
You have to complete the program so that it prints in the reverse order.
Solution:
int j, temp;
j = i - 1; // last Element of the array
i = 0; // first element of the array
while(i < j)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
Question 3
Write a C program to read Two One Dimensional Arrays of same data type (integer type) and merge them into another One Dimensional Array of same type.
Solution:
for (i = 0; i < n2; i++)
scanf("%d", &arr2[i]);
int j;
for(i=0;i<n1;++i)
array_new[i]=arr1[i];
size = n1 + n2;
for(i=0, j=n1; j<size && i<n2; ++i, ++j)
array_new[j] = arr2[i];
Question 4
Write a C Program to delete duplicate elements from an array of integers.
Solution:
int j, k;
for(i = 0; i < size; i++) {
for(j = i + 1; j < size;) {
if(array[j] == array[i]) {
for (k = j; k < size; k++) {
array[k] = array[k + 1];
}
size--;
} else
j++;
}
}
These are Problem Solving Through Programming In C Assignment 6 Answers
More Weeks of Problem Solving Through Programming In C: Click here
More Nptel Courses: Click here
Problem Solving Through Programming In C Week 6 Answers (JAN-APR 2023)
Course Name: Problem Solving Through Programming In C
Course Link: Click Here
These are Problem Solving Through Programming In C Assignment 6 Answers
Q1. 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
Answer: a) An index or subscript in array is a positive integer
Q2. Which of the following is the correct way to declare a one-dimensional integer array named “myArray” with 5 elements in C?
a) int myArray(5);
b) int myArray[5];
c) int myArray = [5];
d) int myArray = {5};
Answer: b) int myArray[5];
These are Problem Solving Through Programming In C Assignment 6 Answers
Q3. The elements of array are stored in contiguous memory due to
a) This way computers can keep track of only the address of the first element and the addresses of other elements can be calculated.
b) The architecture of computer does not allow arrays to store other than serially
c) Both (a) and (b) are true
d) None of these are true
Answer: a) This way computers can keep track of only the address of the first element and the addresses of other elements can be calculated.
Q4.
a) 0
b) 1
c) 5
d) The code will result in a runtime error.
Answer: d) The code will result in a runtime error.
These are Problem Solving Through Programming In C Assignment 6 Answers