0% found this document useful (0 votes)
3 views2 pages

C Programming Exercises on Pointers

The document outlines C programming exercises focused on arrays and pointers. It includes tasks such as reversing an array, removing duplicates, implementing Kadane's algorithm for maximum subarray sum, finding a missing number in a sequence, and printing a matrix in spiral order. Each exercise provides input examples and expected output results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C Programming Exercises on Pointers

The document outlines C programming exercises focused on arrays and pointers. It includes tasks such as reversing an array, removing duplicates, implementing Kadane's algorithm for maximum subarray sum, finding a missing number in a sequence, and printing a matrix in spiral order. Each exercise provides input examples and expected output results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C Programming Exercises: Arrays and

Pointers
1. Reverse Array Using Pointers
Write a C program to reverse an array in-place using only pointers (no array indices).

Input:
arr = [1, 2, 3, 4, 5]

Output:
arr = [5, 4, 3, 2, 1]

2. Remove Duplicates from Array


Write a program to remove duplicate elements from an integer array, keeping only the first
occurrence of each element. Use pointers for manipulation.

Input:
arr = [1, 2, 3, 2, 4, 1, 5]

Output:
arr = [1, 2, 3, 4, 5]

3. Maximum Subarray Sum (Kadane’s Algorithm)


Implement Kadane’s algorithm using pointers to find the subarray with the maximum sum.

Input:
arr = [-2, -3, 4, -1, -2, 1, 5, -3]

Output:
7 (subarray = [4, -1, -2, 1, 5])

4. Find Missing Number in Sequence


Given an array of size n-1 containing numbers from 1 to n, find the missing number. Use
pointers.

Input:
arr = [1, 2, 4, 5], n = 5

Output:
3
5. Print Matrix in Spiral Order
Print the elements of an NxN matrix in spiral order using pointer arithmetic.

Input:
3x3 matrix:
123
456
789

Output:
[1, 2, 3, 6, 9, 8, 7, 4, 5]

You might also like