Explore
ProGrad Programs
About Us

Edit
Reply




Edit

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

Published on 11 Mar 2020

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.


For example, consider the array


Input: arr = {1, 2, 3, 4, 5, 9}

The perfect squares are 1, 4, 9.

Sum = 1 + 4 + 9 = 14


Output: 14


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


C
C++
Java
Python 3

Output
4
1 4 9 16
30


Recommended Programs






If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in