मराठी

Write a program to store 20 numbers in a Single Dimensional Array (SDA). Now, display only those numbers that are perfect squares. n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9] 12 45 49 78 64 77 - Computer Applications

Advertisements
Advertisements

प्रश्न

Write a program to store 20 numbers in a Single Dimensional Array (SDA). Now, display only those numbers that are perfect squares. 

n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
12 45 49 78 64 77 81 99 45 33

Sample Output: 49, 64, 81 

थोडक्यात उत्तर

उत्तर

import java.util.*;
public class AQ9 
{ public static void main(String args[])
{Scanner ob = new Scanner(System.in);
int i, y, a[] = new int[20]; 

System.out.println("Enter 20 numbers");
for (i = 0; i < a.length; i++)
a[i] = ob.nextInt(); 

System.out.println("\nThe numbers that are Perfect Squares are");
for (i = 0; i < a.length; i++)
{y = (int) Math.sqrt(a[i]);
if (a[i] == y * y)
System.out.println(a[i]);
}}}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [पृष्ठ २४१]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
पाठ 3 Arrays (Single Dimensional and Double Dimensional)
EXERCISES | Q VII. 9. | पृष्ठ २४१
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×