- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Square and Square root in Arduino
Arduino has support for several popular math functions, square and square root being among them. Let’s look at the square root first.
Syntax
sqrt(x)
where x is a number of any data type. It returns a double.
For square, you ideally shouldn’t need a separate function. You can just multiply the number by itself.
x_squared = x*x;
However, Arduino does have a separate function for calculating squares. The syntax is −
sq(x) where x is a number of any data type. This again returns a double.
Example
The following example illustrates the use of these functions −
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); float x = 4.0; Serial.println(sqrt(x)); Serial.println(sq(x)); } void loop() { // put your main code here, to run repeatedly: }
Output
The Serial Monitor output is shown below −
- Related Articles
- What is square root and cube root?
- 8086 program to find the square root of a perfect square root number
- What is a number which is a square and square root itself?
- Guess Nearest Square Root in Python
- Fast inverse square root in C++
- What Is the Square Root?
- Check if a number is perfect square without finding square root in C++
- Replace Odd Numbers with Square root & Even Numbers with Square in Java
- C++ Program to count square root cube root and both in given range
- Find the square root of 2025.
- What is mean by square root ?
- Find the square root of 3.5.
- How to find perfect square root?
- Find the square root of 1056.25
- Find the square root of 1250.

Advertisements