b=sqrt(a0
if frac(b)
...
else 'no fraction
...
endif
Also ear in mind that square roots could be negative as well as positive.
a = ltrim rtrim Input ' per togliere caratteri da input tipo CR
if a=0 then exit do
cls
b = sqrt(a)
uses console
int i
double r
print "integer square roots" cr cr
for i=1 to 1000
r=sqr(i)
if frac(r)=0.0
print i tab r cr
endif
next
wait
dim a, b as string
if a = "0" then exit do
include "$/inc/console.inc"
dim a,b as double
global r as int
sub _print()
====================================
if r=1 then
printl "YES is an exact root"
else
printl "NO it is not an exact root"
end if
printl
r=0
end sub
'====== MAIN ===============
do
r=0
printl "input a number: "
'a=input()
a = ltrim rtrim Input ' per togliere caratteri da input tipo CR
if a=0 then exit do
cls
b = sqrt(a)
print "a = " a cr
print "SQRT(a) = " b cr
printl "Text if the result = INT(result)"
if b=int(b) then
r=1
end if
_print
printl "Text if the FRAC(result) has a fractional component"
if frac(b)=0 then
r=1
end if
_print
printl "Text if result = TRUNC(result)"
if b=trunc(b) then
r=1
end if
_print
printl "Test if Result - INT(result) = 0"
if b - int(b) = 0 then
r=1
end if
_print
printl "Test if INT(Result)^2 = number in input"
if int(b)*int(b) = a then
r=1
end if
_print
loop
a = 25
SQRT(a) = 5
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
YES is an exact root
Text if result = TRUNC(result)
YES is an exact root
Test if Result - INT(result) = 0
YES is an exact root
Test if INT(Result)^2 = number in input
YES is an exact root
--------------------------------------------------
a = 63
SQRT(a) = 7.9372539331937721
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
NO it is not an exact root
Text if result = TRUNC(result)
NO it is not an exact root
Test if Result - INT(result) = 0
NO it is not an exact root
Test if INT(Result)^2 = number in input
YES is an exact root
--------------------------------------------------
a = 33
SQRT(a) = 5.7445626465380286
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
NO it is not an exact root
Text if result = TRUNC(result)
NO it is not an exact root
Test if Result - INT(result) = 0
NO it is not an exact root
Test if INT(Result)^2 = number in input
NO it is not an exact root
--------------------------------------------------
a = 50
SQRT(a) = 7.0710678118654755
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
NO it is not an exact root
Text if result = TRUNC(result)
NO it is not an exact root
Test if Result - INT(result) = 0
NO it is not an exact root
Test if INT(Result)^2 = number in input
NO it is not an exact root
--------------------------------------------------
a = 128
SQRT(a) = 11.313708498984761
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
NO it is not an exact root
Text if result = TRUNC(result)
NO it is not an exact root
Test if Result - INT(result) = 0
NO it is not an exact root
Test if INT(Result)^2 = number in input
NO it is not an exact root
--------------------------------------------------
a = 3
SQRT(a) = 1.7320508075688772
Text if the result = INT(result)
NO it is not an exact root
Text if the FRAC(result) has a fractional component
NO it is not an exact root
Text if result = TRUNC(result)
NO it is not an exact root
Test if Result - INT(result) = 0
NO it is not an exact root
Test if INT(Result)^2 = number in input
YES is an exact root
int i
for i=1 to len(a)
print ">>" i tab asc(a,i) cr
next
int i
GetConsoleMode(ConsIn,i)
print "Cons input mode: " hex (i) cr
print "a = " a cr
print "SQRT(a) = " b cr
SetConsoleMode(ConsIn,0x1B7)
Under Microsoft Windows [Version 10.0.15063], attempting to use the WriteConsoleW low-level API to output to the console results in no text being printed under WSL.
if b=int(b) then r=1 : end if
uses console
double g=5/3
print "g =" tab g cr
print "cast" tab str((int) g) cr
print "cast" tab str(cast int g) cr
print "convert" tab str(convert int g) cr
wait
function dp_str(string num="", int wid=20, dpp=10) as string
===========================================================
'num number string
'wid column width
'dpp decimal point position in column
'
string buf 'column buffer
int ln 'length of num
int dp 'offset of num decimal point
'
buf=space(wid) ' column string
ln=len(num)
dp=instr(num,".")
if dp=0 'integers
dp=ln+1
endif
'
int n=dpp-dp 'left spaces
'check if too long
if n<0 then n=0 'remove left space
if ln>wid
mid buf,1,"!!"+num 'error
else
mid(buf,1+n,num) 'copy number into position
endif
return buf
end function
'TESTS
uses console
print dp_str(pi(),30) "|" cr
print dp_str(pi(),30,4) "|" cr
print dp_str(str(pi(),5)) "|" cr
print dp_str(12345678) "|" cr
print dp_str(123) "|" cr
print dp_str(-123) "|" cr
print dp_str(-123.45) "|" cr
wait
uses corewin
uses console
char buf[100]
double d=pi()
char buf[100]
double d=pi()
'sprintf_s(buf,100,"floats: %4.2f %+.0e %E " cr, d, d, d)
'sprintf(buf, "floats: %4.2f %+.0e %E " cr, d, d, d)
sprintf (buf, "Characters: %c %c ", asc("a"), 65)
print buf cr
sprintf (buf, "Decimals: %d %ld", 1977, 650000L)
print buf cr
sprintf (buf, "Preceding with blanks: %10d ", 1977)
print buf cr
sprintf (buf, "Preceding with zeros: %010d ", 1977)
print buf cr
sprintf (buf, "Some different radices: %d %x %o %#x %#o ", 100, 100, 100, 100, 100)
print buf cr
sprintf (buf, "floats: %4.2f %+.0e %E", double 3.1416, double 3.1416, double 3.1416)
print buf cr
sprintf (buf, "Width trick: %*d", 5, 10)
print buf cr
sprintf (buf, "%s", "A string")
print buf cr
print cr
wait
...
function SetFont(sys *hwnd,n,height,width,weight,string fontname) as sys
========================================================================
indexbase 1
sys hFont,i
hfont=CreateFont( height,width,0,0,weight,0,0,0,0,0,0,0,0,fontname)
int i
for i=1 to n
SendMessage hwnd(i),WM_SETFONT,hfont,0
next
return hFont
end function
...
hFont=SetFont(hchw[1],6,13,9,400,"Lucida console")