IGNOU BCSL-032-C++ Programming Lab, Latest Solved Assignment (July 2023 - January 2024 )

ignoustudymentor.com

Q2. Write a program in C++ to find the sum of elements in an array using Function Template. Make necessary assumptions.

Ans.

#include <iostream>

template <typename T>
T sum_array(T array[], int size) {
    T sum = 0;
    for (int i = 0; i < size; i++) {
        sum += array[i];
   }
   return sum;
}

int main() {
    int array[] = {1, 2, 3, 4, 5};
    int size = sizeof(array) / sizeof(array[0]);

    int sum = sum_array(array, size);
    std::cout << “The sum of the array is: ” << sum << std::endl;

return 0;
}

ignoustudymentor.com

BCSL-032

Handwriting Assignment

BCSL-032

Other Questions With Answers

Other Subjects

Click Here

Assignment Submission Last Date

The IGNOU open learning format requires students to submit study Assignments. Here is the final end date of the submission of this particular assignment according to the university calendar.

30th April (if Enrolled in the June Exams)

31st October (if Enrolled in the December Exams)

Student Quick Services

error: Content is protected !!