Computer Science, asked by vanushree611, 10 months ago

write a program to store 20 number in single dimensional array display only those numbers that are perfect square and sum of those numbers which are not perfect square
int a[]={12,45,49,78,64,77,81,99,45,33}

output
49
64
81
sum of number which are not perfect square___​

Answers

Answered by manjumishra1231972
15

Answer:

import java.util.Scanner;

public class KboatSDASquares

{

public void displayPerfectSquares() {

Scanner in = new Scanner(System.in);

int arr[] = new int[20];

System.out.println("Enter 20 numbers");

for (int i = 0; i < arr.length; i++) {

arr[i] = in.nextInt();

}

System.out.println("Perfect Squares are:");

for (int i = 0; i < arr.length; i++) {

double sr = Math.sqrt(arr[i]);

if ((sr - Math.floor(sr)) == 0)

System.out.print(arr[i] + ", ");

}

}

}

Answered by vishakasaxenasl
0

Answer:

Following Python program will perform the desired function. Just copy and paste it in any python ide.

Explanation:

import math

num = list(map(int, input().split(",")))

for i in num:

 root = math.sqrt(i)

 if(int(root + 0.5) ** 2 == num):

      print(num)

else:

     sum += num

print(sum)

#SPJ3

Similar questions