6 Arrays

C Programming · Unit 6 · 6 hrs

Arrays

Exam-focused notes for Arrays (C Programming, CSC115): what the TU syllabus asks and how it has actually been tested, with 10 solved past questions from this unit.

What this unit covers

  • Introduction to Array
  • Types of Array (Single Dimensional and Multidimensional)
  • Declaration and Memory Representation of Array
  • Initialization of array
  • Character Array and Strings
  • Reading and Writing Strings
  • Null Character
  • String Library Functions (string length, string copy, string concatenation, string compare)

Introduction to Array

208110 marks

What are the characteristics of array?Write a program to input age of 500 persons and display the following: a) Average age b) Age between 25 to 30[2+8]

An array is a collection of similar data type elements stored in contiguous memory locations. Its main characteristics are: 1. Homogeneous Elements: All elements in an array must be of the same data type (e.g., all int, all float). 2. Contiguous Memory Allo...

Full solved answer →
20795 marks

Write a program to find the second largest number in the given array of numbers. [5]

1. Read N numbers into an array. 2. Find the largest element first. 3. Then find the largest element among all elements that are NOT equal to the largest -- that gives the second largest. --- --- --- Step What happens ------------------- First loop Reads N ...

Full solved answer →
207510 marks

Define array?What are the benefits of using array?Write a program to add two matrices using array.[1+2+7]

--- An array is a collection of similar (same data type) elements stored in contiguous memory locations, referred to by a single variable name and accessed using an index (subscript). Syntax: Example: --- Benefit Explanation ------ Organized Storage Multipl...

Full solved answer →
20745 marks

Write a program to find sum and average of 10 integer numbers stored in an array. [5]

Arrays use a loop variable as the subscript (starting from 0) to process elements. A one-dimensional array of size 10 has indices from arr[0] to arr[9]. Step Description ------------------- int arr[10] Declares a one-dimensional array of 10 integers (indice...

Full solved answer →

Types of Array

20805 marks

Write a program to read P*Q matrix of integers and find the largest integer of each row and display it. [5]

A two-dimensional array is declared as datatype arrayname[row][col]. Processing requires a nested loop where the outer loop corresponds to rows and the inner loop corresponds to columns. Each element can be accessed as a[i][j]. --- 1. Start 2. Read the numb...

Full solved answer →
207710 marks

What are the benefits of using arrays?Compare one dimensional array with two dimensional array.Write a program to find transpose of a matrix.[2+2+6]

--- (a) Benefits of Using Arrays An array is a collection of elements of the same data type stored in contiguous memory locations under a single variable name. Benefits of using arrays: 1. Easy data management: Multiple values of the same type can be stored...

Full solved answer →

Character Array and Strings

20805 marks

Write a program to check whether the entered word is palindrome or not. [5]

A palindrome is a word (or string) that reads the same forwards and backwards. For example: madam, level, racecar are palindromes. 1. Accept a word (string) from the user. 2. Copy the original string into another variable. 3. Reverse the copied string using...

Full solved answer →

Initialization of array

20805 marks

Write a program to initialize an array of dimension 10 and sort the numbers within the array in ascending order. [5]

The program initializes an array of dimension 10, reads values from the user, and sorts them in ascending order using Bubble Sort. Bubble Sort Logic: Compare adjacent elements; if the left element is greater than the right, swap them. Repeat for n-1 passes....

Full solved answer →

String Library Functions

207810 marks

Explain any three string functions.Write a program to check if two matrices are identical or not.[3+7]

(a) Three String Functions String functions are built-in functions available in the <string.h header file used to manipulate strings in C. --- Returns the number of characters in a string, excluding the null character \0. Syntax: int strlen(char s[]); Examp...

Full solved answer →
20755 marks

Discuss any five string library functions. [5]

String library functions are built-in functions used to manipulate strings in C. Their prototypes are declared in the header file <string.h. --- This function returns the length of the string, i.e., the number of characters excluding the terminating null ch...

Full solved answer →