Computer Science, asked by monuamitcool6106, 8 months ago

Write a Java program to input 10integer elements and print the sum of all the palindrome numbers

Answers

Answered by Anonymous
0

Answer:

// C++ program to calculate the sum of all

// palindromic numbers in array

#include<bits/stdc++.h>

using namespace std;

// Function to reverse a number n

int reverse(int n)

{

int d = 0, s = 0;

while (n > 0)

{

d = n % 10;

s = s * 10 + d;

n = n / 10;

}

return s;

}

// Function to check if a number n is

// palindrome

bool isPalin(int n)

{

// If n is equal to the reverse of n

// it is a palindrome

return n == reverse(n);

}

// Function to calculate sum of all array

// elements which are palindrome

int sumOfArray(int arr[], int n)

{

int s = 0;

for (int i = 0; i < n; i++)

{

if ((arr[i] > 10) && isPalin(arr[i]))

{

// summation of all palindrome numbers

// present in array

s += arr[i];

}

}

return s;

}

// Driver Code

int main()

{

int n = 6;

int arr[] = { 12, 313, 11, 44, 9, 1 };

cout << sumOfArray(arr, n);

return 0;

}

Similar questions