Number of perfect squares between two given numbers

preview_player
Показать описание
MATLAB CODE:

x=input('Enter the first number:');
y=input('Enter the second number');
c=0;
for i=x:y
z=sqrt(i);
a=ceil(z);
if(a==z)
c=c+1;
end
end
disp('The total no of perfect square numbers in the range is:');
disp(c);

Check my previous video on algorithm of checking perfect square number:

Рекомендации по теме
Комментарии
Автор

CODE:






import java.util.Scanner;
import java.lang.Math;
class Example
{
public static void main(String args[])
{
System.out.println("Enter the first number:");
Scanner obj=new Scanner(System.in);
int x=obj.nextInt();
double z=0;
double a=0;
int c=0;
System.out.println("Enter the second number:");
int y=obj.nextInt();
for(int i=x;i<=y;i++)
{
z=Math.sqrt(i);
a=Math.ceil(z);
if(a==z)
{
c=c+1;
}
}
System.out.println("Total no:"+c);
}
}

KnowledgeAmplifier