Program to find the sum of perfect square elements in an array | faceprep

Program to find the sum of perfect square elements in an array | faceprep

The program to find the sum of perfect square elements in an array is discussed here. An array is given as input and the sum of all the perfect square elements present in the array is produced as output.

Program to find the sum of perfect square elements in an array


For example, consider the array

Input: arr = {1, 2, 3, 4, 5, 9}nThe perfect squares are 1, 4, 9.nSum = 1 + 4 + 9 = 14nOutput: 14n


Algorithm to find the sum of perfect square elements in an array

  • Input the number of elements of the array.
  • Input the array elements.
  • Initialize sum = 0.
  • Check if the array element is a perfect square.
  • If it is a perfect square, sum = sum + num.
  • Return sum.


program to find the sum of perfect square elements in an array

Program to find the sum of perfect square elements in an array

@@coding::1@@


Recommended Programs


Program to find the sum of perfect square elements in an array

c