Questions tagged [perfect-square]

Perfect square is an element of algebraic structure which is equal to the square (algebra) of another element.

87 questions
0
votes
2 answers

Checking if array length is a perfect square

I am trying to write an if statement to check to see if the amount of numbers a user enters into the array is a perfect square (4, 9, 25, 36...). if(array.length != Math.sqrt(array)) I know this isn't correct and I know it is probably something…
TyngeOfTheGinge
  • 524
  • 1
  • 4
  • 14
0
votes
3 answers

Is there a BATCH/CMD command that checks if a number is a perfect square?

I'm trying to write a program in Batch that puts numbers into simplified radical form. Is there a way to check if a number is a perfect square?
0
votes
1 answer

Redundant Pattern Matching

I am trying to write a function that finds whether or not a given number n is a perfect square. Here's my attempt: local fun perfect_square_iter x z = let val sqr = z * z in case (x,z) of (sqr,_) => true | (_, 0) => false |…
Langston
  • 1,083
  • 10
  • 26
0
votes
6 answers

How do I square a number's digits?

How do I square a number's digits? e.g.: square(21){}; should result in 41 instead of 441
HomeBrainBox
  • 23
  • 1
  • 7
0
votes
1 answer

python, square finder, memory error

I've been working on a problem to find whether or not a given integer n is a perfect square. Although the algorithm works, I get a MemoryError. How should I rephrase this code bit? Thanks in advance. def is_square(n): for i in range(1,…
0
votes
3 answers

Writing a Python program that finds the square of a number without using multiplication or exponents?

thank you for reading and hopefully responding to my question. I'm stuck trying to write this Python program that finds a number's square without using multiplication or exponents. Instead, I have to get the summation of the first odd n numbers…
obtusefairy
  • 1
  • 1
  • 2
0
votes
3 answers

How to take the square of a number in Android

I'm trying to make a number squared (for example, x^2) in Android code, but I get this error: The operator ^ is undefined for the argument type(s) int, boolean is there a different way to square a number/variable in Android?
David Elliott
  • 113
  • 1
  • 3
  • 10
0
votes
1 answer

Extract r^2 from multiple models in plyr

I am hoping to efficiently combine my regressions using plyr functions. I have data frames with monthly data for multiple years in format yDDDD (so y2014, y2013, etc.) Right now, I have the below code for one of those dfs, y2014. I am running the…
Z_D
  • 797
  • 2
  • 12
  • 30
0
votes
5 answers

Square list of numbers user input Python

i'm trying to write a function where user can input a list of numbers, and then each number gets squared, example [1,2,3] to [1,4,9]. so far my code is this: def squarenumber(): num = raw_input('Enter numbers, eg 1,2,3: ').split(',') print…
zenoh
  • 2,071
  • 1
  • 22
  • 38
0
votes
2 answers

Prolog - generate and test, how to write a rule square(S)

I have to write a rule square(S) in Prolog that tests if a number S is the square of an integer returning false (ex. square(3)) or true (ex. square(4)). I used already a rule that generates all integers between 0 and M: isInteger(X,M) :-…
user1336326
  • 71
  • 1
  • 8
0
votes
3 answers

Perfect square in fibonacci sequence?

Create a program to find out the first perfect square greater than 1 that occurs in the Fibonacci sequence and display it to the console. I have no output when I enter an input. #include #include int PerfectSquare(int n); int…
redundant6939
  • 153
  • 3
  • 5
  • 16
0
votes
2 answers

Perfect Square function not working properly?

It should return false when the number does not have perfect square, otherwise it returns the root. But in this code it returns the root all the time. E.g. Input 5, root 2. main() { int i; int number=0; int result=0; for(i=0; i<10; i++){ …
redundant6939
  • 153
  • 3
  • 5
  • 16
-1
votes
5 answers

Return the first perfect square that is greater than its integer argument

I need to write a function that returns the first perfect square that is greater than its integer argument. A perfect square is an integer that is equal to some integer squared. For example 16 is a perfect square because 16 = 4 * 4. However 15 is…
Maged Samaan
  • 1,742
  • 2
  • 19
  • 39
-1
votes
1 answer

How do I display all perfect squares below a given number on scratch?

I was able to list all the prime numbers up to an inputted number, however as I am inexperienced at coding on Scratch, I have had difficulty constructing a list of all the perfect squares below a number. For example, if you input 17 the output…
KimJongin
  • 13
  • 4
-1
votes
4 answers

Square Pair numbers

So i've been attempting this problem for the last few days and have no luck. I am tasked to find square pairs from 1 to x. Num1 + Num2 = a perfect square (i.e. 2 + 2 = 4. 16 + 20 = 36) Num2 - Num1 = a perfect square. (i.e. 2 - 2 = 0. 20 - 16 =…
King Twix
  • 52
  • 8