0% found this document useful (0 votes)
7 views

arraypdf

Array in c

Uploaded by

sridharshini1405
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

arraypdf

Array in c

Uploaded by

sridharshini1405
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

1.

Array rotation for k times(left or right)

Left:
Right:
2.Give c program to print the number of occurance of a number in an array
3.Sum and Product
4.Print square of the elements in an array
5.Difference between maximum and minimum element of an array
6.Count of array elements divisible by specific number
7.Sum the array after removing duplicate elements
8. Print negative elements in array
9.Print the peak elements in array
10.Print the count of positive numbers
11..Delete the element in the given position in an array
12.sum of duplicates in an array

13.sum of even numbers in an array


14.find the non prime numbers in an array
15.Given an Array print only the Positive numbers Sample Input: [1,3,-4,-5,2,3]
Sample Output: [1,3,2,3]
16..replace the peak number by adding it neighbour elements (example:- input: 1 2
4 3 output: 1 2 9 3 )
17.Print the sum of first element, second element,last element,second last element
in an array Example : [1,2,4,5,5] Output: 1+2+5+5 = 13, [1,2,3] Output : 4
18.Print the median of an array after sorting
19.Print the average of an array
20.Array Input range 2-10 if exceeds print "Invalid". print two elements which is the
sum of two element closest to 0(zero). Input: [-1,-10,8,2] output: [-1,2].
Explanation -1+2=-1 is the closest to 0 than other combinations.
21.print the unique elements in array Example: input = [0,5,3,5,2,3] output = 0 and 2

22.Find the second largest element in the array


23.Find the count of repeated element in array
24.Sort the array in ascending order and print even numbers first and odd numbers
next
25.Removing even numbers from an array
26.Removing first occurence of a given number from an array

27.Array Chunking - Eg1 : Chunk size = 2, array size 8, elements (1,2,3,4,5,6,7,8) -


Ans : [1,2] [3,4] [5,6] [7,8] Eg2: Chunk size = 3, array size 4,

elements (1,2,3,4) - Ans : [1,2,3]

29.Count the total number of duplicate elements in an array


You are given an array of integers. Your task is to count the total number of duplicate
elements in the array.
.TEST CASE 2:
Input: [1, 2, 2, 3, 4, 4, 4, 5, 5]
Output: 3
Explanation: The duplicate elements are 2, 4, and 5.

30.Count the frequency of each element of an array.


You are given an array of integers. Your task is to count the frequency of each element
inthe array and return a dictionary where keys are the unique elements in the array
andvalues are their frequencies.
TEST CASE 2:
Input: [1, 2, 2, 3, 4, 4, 4, 5]
Output:
1 occurs 1 times
2 occurs 2 times
3 occurs 1 times
4 occurs 3 times
5 occurs 1 times
Explanation: Each element appears only once in the array.

31.Find a pair with a given sum .


Write a program to find a pair with a given sum in the array.

\
32.Move all 0's
Given an integer array nums, move all 0's to the end of it while maintaining the
relative
order of the non-zero elements.Note :that you must do this in-place without making
a
copy of the array.
TEST CASE 1:
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]
TEST CASE 2:
Input: nums = [0]
Output: [0]
TEST CASE 3:
Input: nums = [0,1]
Output: [1,0]
33.Delete the Element from Array
Write a program to delete elements from the array at specified position. How to
remove
elements from an array at a given position. Logic to remove elements from any given
position in an array. The program should also print an error message if the delete
position

34.Merge two array to third array


Write a program to input elements in two array and merge two array to the third array.
How to merge two array. Logic to merge two sorted array to third array.

35.Product of array except self.


Given an integer array nums, return an array answer such that answer[i] is equal to
the
product of all the elements of nums except nums[i].
Input: nums = [1,2,3,4]
Output: [24,12,8,6]
TEST CASE 2:
Input: nums = [-1,1,0,-3,3]
Output: [0,0,9,0,0]

36.Maximum Distance Between Same Elements


Given an array with duplicate elements, find the maximum distance between two
occurrences of the same element.
TEST CASE 1:
Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]
Output: 9

37.How Many Numbers Are Smaller Than the Current Number.


Given the array nums, for each nums[i] find out how many numbers in the array are
smaller than it. That is, for each nums[i] you have to count the number of valid
j's such
that j != i and nums[j] < nums[i].
Return the answer in an array.
38.Count Smaller Elements on Right Side
Given an array of integers, for each element, count the number of elements on its
right
side that are smaller than it.
39.Separate the digits in an array.
Given an array of positive integers nums, return an array answer that consists of the
digits
of each integer in nums after separating them in the same order they appear in nums.
To separate the digits of an integer is to get all the digits it has in the same order.
For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].

40.Write a program to read elements in a matrix and check whether the given matrix
isa symmetric matrix or not.A matrix is considered a symmetric matrix if it is equal to
its transpose, i.e., A = A^T. Inother words, a square matrix is symmetric if the
elements across the main diagonal areequal.
TEST CASE 1:
Input:
Enter the number of rows: 3
Enter the number of columns: 3
Enter element [0][0]: 1
Enter element [0][1]: 2
Enter element [0][2]: 3
Enter element [1][0]: 2
Enter element [1][1]: 4
Enter element [1][2]: 5
Enter element [2][0]: 3
Enter element [2][1]: 5
Enter element [2][2]: 6

You might also like