

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- 8086 program to find the square root of a perfect square root number
- Guess Nearest Square Root in Python
- Fast inverse square root in C++
- Check if a number is perfect square without finding square root in C++
- C++ Range Sum Queries and Update with Square Root
- C++ Program to count square root cube root and both in given range
- Babylonian method to find the square root
- Square root function without using Math.sqrt() in JavaScript
- 8085 program to find square root of a number
- 8086 program to find Square Root of a number
- Count square and non-square numbers before n in C++
- How to find Square root of complex numbers in Python?
- Get square root of a number using Math.sqrt in Java
- How to get the square root of 2 in JavaScript?
- How to calculate square root of a number in Python?
Advertisements