Problem Solving Through Programming In C Week 6
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 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
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 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
Q5.

Answer: 150
Q6. What is the maximum dimension of an array allowed in C?
a) 10
b) 100
c) 1000
d) No such limit exists
Answer: d) No such limit exists
These are Problem Solving Through Programming In C Assignment 6 Answers
Q7.

a) 1 followed by two garbage values
b) 1 1 1
c) 1 0 0
d) 0 0 0
Answer: c) 1 0 0
Q8. A one-dimensional array X has indices 1….50. Each element is an int. The array is stored at location 1000 decimal. The starting address of X[27] is ______(assume int takes 4 bytes).
Answer: 1104
These are Problem Solving Through Programming In C Assignment 6 Answers
Q9. Which of the following statements finds the minimum value in an integer array named “myArray” in C?




Answer: c)
Q10. 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
These are Problem Solving Through Programming In C Assignment 6 Answers
Problem Solving Through Programming In C Programming 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;
i = 0;
while (i<j)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
These are Problem Solving Through Programming In C Assignment 6 Answers
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:
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
C Program to delete an element from a specified location of an Array starting from array[0] as the 1st position, array[1] as second position and so on.
Solution:
for (i = pos - 1; i < num - 1; i++)
{
array[i] = array[i+1];
}
num--;
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: 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 6 Answers
Q1. What is the right way to initialise an array in C?
a) int ar{}= {1,2, 5,6,9}
b) int ar[5]= {1,2, 5,6,9}
c) int ar {5} = {1,2, 5,6,9}
d) int ar()= {1,2, 5,6,9}
Answer: b
Q2. An 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 9th 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: b
Q3. What will be the output after execution of the program?
Answer: a
These are Problem Solving Through Programming In C Assignment 6 Answers
Q4. Which of the statements is/are correct?
a) An array may contain 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
Q5. What actually gets passed when you pass an array as an argument to a function
a) Value of elements in array
b) First element of the array
c) Base address of the array
d) Address of the last element of array
Answer: c
Q6. Find the output of the following C program
Answer: c
These are Problem Solving Through Programming In C Assignment 6 Answers
Q7. What will be the output?
Answer: c
Q8. An array of the void data type
a) can store any data-type
b) only stores element of similar data type to first element
c) acquires the data type with the highest precision in it
d) It is not possible have an array of void data type
Answer: d
Q9. What will be the output?
Answer: 20
These are Problem Solving Through Programming In C Assignment 6 Answers
Q10. How many ‘a’ will be printed when the following code is executed?
Answer: 6
Programming Assignment Answers
These are Problem Solving Through Programming In C Assignment 6 Answers
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:
//Code
These are Problem Solving Through Programming In C Assignment 6 Answers
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:
//Code
These are Problem Solving Through Programming In C Assignment 6 Answers
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:
//Code
These are Problem Solving Through Programming In C Assignment 6 Answers
Question 4
Write a C Program to delete duplicate elements from an array of integers.
Solution:
//Code
These are Problem Solving Through Programming In C Assignment 6 Answers
More NPTEL Solution: https://progiez.com/nptel

This content is uploaded for study, general information, and reference purpose only.