0% found this document useful (0 votes)
14 views11 pages

Programming Fundamentals LAB 9

The document outlines a series of programming tasks related to C++, focusing on array manipulation, pointer usage, and memory management. Each task includes a brief description of the problem, followed by a placeholder for the solution and output. The tasks cover various concepts such as summing array elements, inserting and deleting elements, working with 2D arrays, and implementing search algorithms.
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)
14 views11 pages

Programming Fundamentals LAB 9

The document outlines a series of programming tasks related to C++, focusing on array manipulation, pointer usage, and memory management. Each task includes a brief description of the problem, followed by a placeholder for the solution and output. The tasks cover various concepts such as summing array elements, inserting and deleting elements, working with 2D arrays, and implementing search algorithms.
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
You are on page 1/ 11

Programming Fundamentals(ADCS-1)

Lab Task#8
SAIF UR REHMAN
Q1# Write a C++ program that initializes an array with
5 float numbers and calculates the sum of these
numbers. Display the sum.
Solution:

Output:

Q2# Write a C++ program that allows the user to


insert a new element at a specific index in an array of
integers?
Solution:

Output:

Q3# Write a C++ program that deletes an element


from an array at a specified index and shifts the
remaining elements to maintain order. Print the
updated array?
Solution:

Output:

Q4# Write a C++ program to declare and initialize a


2D array (3x3) with values from 1 to 9. Print the 2D
array in matrix form?
Solution:

Output:

Q5# Write a C++ program that declares an


integer variable, assigns a value to it, and then uses a
pointer to change the value of that variable. Print the
value before and after the change?
Solution:
Output:

Q6# Write a C++ program that initializes an array of


integers and uses pointer arithmetic to print the
elements of the array?
Solution :

Output:

Q7:# Write a program that initializes an array of 5


integers and uses pointer arithmetic to print the
elements of the array.
Solution:
Output:

8- Write a C++ program that dynamically allocates


memory for an array of integers based on user input.
After storing the values, print the array and free the
allocated memory.
Solution:

Output:
Q9-Write a function that swaps two integers using
pointers. Demonstrate the function in a main program
by swapping two user-input integers.
Solution:

Output:
10- Write a C++ program that implements a linear
search algorithm to find a specific element in an
array. If the element is found, print its index;
otherwise, print a message indicating it was not
found?
Solution:

Output:
11- Write a C++ function that takes an integer array
and its size as parameters and returns the maximum
value in the array using pointers.
Solution:

Output:

Q12- Write a C++ program that swaps two integers


using pointers. Write a function that takes two
integer pointers as parameters and swaps their
values.
Solution:

Output:

You might also like