Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Practice Assignment on CSD 101 Intro to computing and programming, Assignments of Introduction to Computing

Based on C language including arrays, pointers.

Typology: Assignments

2021/2022

Available from 10/13/2022

mansi-kulshreshtha
mansi-kulshreshtha 🇮🇳

4 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Generate an array of n (n is in [20, 30]) integers. Write a function to find (a) the smallest even
numbers, (b) the largest even number and (c) the greatest common divisors (GCD) of these
two numbers.
2. Take an array of 20 integers. Now write functions to find the sum of a pair of prime numbers
whose sum is also present in the array. To do this task, you may do the following:
1) Write a function to take the first prime number that appears in the array and find the next
prime number subsequent to the first prime number. Add their sum and check whether the
sum is present in the array or not? (Hint: Here 3 and 5 are subsequent prime numbers whose
sum (= 8) is present in the array)
2) Repeat the same for all pairs of prime numbers in the array and print the pairs of
subsequent prime number and their sum.
3. Assume an integer array. Find a sub-array of length 3 whose reverse order can also be found
in the same array. For example, the sub-array 4 5 6 appears as 6 5 4 (found in the same array).
Print the start and end positions of all such sub-arrays and its reverse order in the array.
4. Generate an array of n integers where n is an integer between 20 and 60. Write recursive
functions to do the following tasks: (a) the smallest even number, (b) the largest odd number
and (c) the largest prime factor among the factors of all elements in the array.
5. Take an array of 20 integers. Now write a recursive function to identify the following task: A
subarray can repeat in the same array with a constant multiplied with each element of the
subarray. For example, consider the following subarray: 2 3 7. Multiplying each element with
a constant 3 gives 6 9 21 which is also present in the array. Find all such subarrays of length 3.
6. Write a program to reverse an array, without using any additional array.
7. Write a program to list all the prime numbers of an array, alongwith their respective positions
in the array.
8. Write a C program to take a square matrix as input, and check whether the given
matrix is orthogonal or not. You should take the input in main function and pass the
2D pointer to a function to do the calculations and checking.
[Hint: The matrix A is said to be orthogonal if AAT=I, where I is the identity matrix.]
9. Write a program to take a 2D array as input. Your main function should check for the eligibility
of the 2D matrix to have an inverse. It will pass the 2D array to a function to calculate the
inverse of the matrix, and return the pointer to the inverse matrix, to the main function, where
it will be printed.
10. Write a program to input a 2D integer array and send the pointer to a function. Your function
will find out the rows with the maximum and minimum sum.

Partial preview of the text

Download Practice Assignment on CSD 101 Intro to computing and programming and more Assignments Introduction to Computing in PDF only on Docsity!

  1. Generate an array of n (n is in [20, 30]) integers. Write a function to find (a) the smallest even numbers, (b) the largest even number and (c) the greatest common divisors (GCD) of these two numbers.
  2. Take an array of 20 integers. Now write functions to find the sum of a pair of prime numbers whose sum is also present in the array. To do this task, you may do the following:
    1. Write a function to take the first prime number that appears in the array and find the next prime number subsequent to the first prime number. Add their sum and check whether the sum is present in the array or not? (Hint: Here 3 and 5 are subsequent prime numbers whose sum (= 8) is present in the array)
    2. Repeat the same for all pairs of prime numbers in the array and print the pairs of subsequent prime number and their sum.
  3. Assume an integer array. Find a sub-array of length 3 whose reverse order can also be found in the same array. For example, the sub-array 4 5 6 appears as 6 5 4 (found in the same array). Print the start and end positions of all such sub-arrays and its reverse order in the array.
  4. Generate an array of n integers where n is an integer between 20 and 60. Write recursive functions to do the following tasks: (a) the smallest even number, (b) the largest odd number and (c) the largest prime factor among the factors of all elements in the array.
  5. Take an array of 20 integers. Now write a recursive function to identify the following task: A subarray can repeat in the same array with a constant multiplied with each element of the subarray. For example, consider the following subarray: 2 3 7. Multiplying each element with a constant 3 gives 6 9 21 which is also present in the array. Find all such subarrays of length 3.
  6. Write a program to reverse an array, without using any additional array.
  7. Write a program to list all the prime numbers of an array, alongwith their respective positions in the array.

8. Write a C program to take a square matrix as input, and check whether the given

matrix is orthogonal or not. You should take the input in main function and pass the

2D pointer to a function to do the calculations and checking.

[Hint: The matrix A is said to be orthogonal if AAT=I, where I is the identity matrix.]

  1. Write a program to take a 2D array as input. Your main function should check for the eligibility of the 2D matrix to have an inverse. It will pass the 2D array to a function to calculate the inverse of the matrix, and return the pointer to the inverse matrix, to the main function, where it will be printed.
  2. Write a program to input a 2D integer array and send the pointer to a function. Your function will find out the rows with the maximum and minimum sum.