Job Saarnee

JOB SAARNEE

Top Most Platform for Job Updates O Level Results Answer keys AKTU MCQs

Unit 4 Most Frequently asked Question with answer | Most important question of PPS

 Unit 4 Most Frequently asked Question with answer | Most important question of PPS
Q1 What is an array? Explain about various operations of an array?
Solution:

In C programming language, an array is a collection of elements of the same type, stored in contiguous memory locations. The elements of an array can be accessed using an index, which represents the position of an element in the array.
The syntax to declare an array in C is:
type array_name[array_size];
where type is the data type of the elements in the array, array_name is the name of the array, and array_size is the number of elements in the array.
For example, to declare an array of integers with 5 elements, you would write:
int my_array[5];
The elements in the array are numbered from 0 to size-1, so the first element in the array is my_array[0], the second element is my_array[1]
Here are some of the operations that can be performed on arrays:
Initialization: Arrays can be initialized with values when they are declared, or their values can be set later using an assignment statement.
Example: int arr[5] = {1, 2, 3, 4, 5};
Accessing elements: The elements of an array can be accessed using their index. The index starts at 0 and goes up to the size of the array minus 1.
Example: int value = arr[2];
Modifying elements: The elements of an array can be modified by assigning a new value to the element using its index.
Example: arr[2] = 6;
Traversing an array: An array can be traversed using a loop, such as a for loop. This allows us to access and process each element of the array in turn.
Example:
for (int i = 0; i < 5; i++) {
    printf(“%d “, arr[i]);
}
Searching an array: We can search for a specific element in an array by iterating through the array and checking each element until we find the desired element.
Example:
int search(int arr[], int size, int key) {
    for (int i = 0; i < size; i++) {
        if (arr[i] == key) {
            return i;
        }
    }
    return -1;
}
This function takes an array, its size, and a key value to search for, and returns the index of the first occurrence of the key value in the array. If the key value is not found in the array, it returns -1.
Sorting an array: We can sort the elements of an array in ascending or descending order using sorting algorithms like bubble sort, selection sort, or quicksort.
Example:
void bubble_sort(int arr[], int size) {
    for (int i = 0; i < size – 1; i++) {
        for (int j = 0; j < size – i – 1; j++) {
            if (arr[j] > arr[j+1]) {
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
}
This function implements the bubble sort algorithm to sort the elements of an integer array in ascending order.
These are some of the basic operations that can be performed on arrays. Arrays are a fundamental data structure in computer programming and are used extensively in many applications.


Q2 Write a program to multiply two matrices?
or
Write a program in C to multiply the two matrices of N X N?
or
Write a C program to find the multiplication of two matrices?
or
Write a program to multiply two matrices of dimensions 3 X 3 and store the results in another matrix?

Q3 Write a C program to sort set of integers is ascending order by using bubble sort technique?
or
Write a program in C sort list of 10 integers in an ascending order
or
Write a program to sort an array of integers in ascending order using bubble sort?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

You cannot copy content of this page