Computer Science, asked by arpanseal327, 5 months ago

write the program to display all numbers between m and n input the keyboard check and display the nos that are prefect square are said t ​

Answers

Answered by renu43796
0

Answer:

C program to display all numbers between m and n input from the keyboard (where m0, n>0), check and print the numbers that are a perfect square

Explanation:

1= 1^2; 4= 2^2; 9= 3^2; 16= 4^2; 25= 5^21=12;4=22;9=32;16=42;25=52

Hence, the perfect squares are numbers : 1, 4, 9, 16, 25, etc.

C Program To Find Perfect Squares Between Two Numbers

#include<stdio.h>

#include<math.h>

int main(){

   int i,j,m,n;

   float ps;

   printf("enter the first number\n");

   scanf("%d",&m);

   printf("enter the last number\n");

   scanf("%d",&n);

   printf("perfect squares between %d and %d:",m,n);

   for(j=m+1;j<n;j++){

   ps=sqrt(j);

   i=(int)ps;

   if(i==ps){

       printf("%d\n",j);

   }

}

   return 0;

}

Output

enter the first number                                                                                              

5                                                                                                                    

enter the last number                                                                                              

100                                                                                                                  

perfect squares between 5 and 100:                                                                                   9                                                                                                                    

16                                                                                                                  

25                                                                                                                  

36                                                                                                                  

49                                                                                                                  

64                                                                                                                  

81

Answered by anindyaadhikari13
2

Question:-

Write a program to display all numbers between m and n taking input from keyboard. Check and display the numbers that are perfect squares.

Program:-

import java.util.*;

class Program

{

static boolean isPerfectSquare(int n)

{

double s=Math.sqrt(n);

return (s==(int)s);

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the starting range: ");

int m=sc.nextInt();

System.out.print("Enter the ending range: ");

int n=sc.nextInt();

// if m>n then we will swap them.

if(m>n)

{

int t=m;

m=n;

n=t;

}

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

{

if(isPerfectSquare(i))

System.out.println(i+" is a Perfect Square.");

}

}

}

Similar questions