Determine Recursively Whether a Given Number is Even or Odd in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 07:09:21

372 Views

StepsTake a number from the user and store it in a variable.Pass the number as an argument to a recursive function.Define the base condition as the number to be lesser than 2.Otherwise, call the function recursively with the number minus 2.Then, return the result and check if the number is even or odd.Print the final result.Enter a number: 124Number is even!Enter a number: 567Number is odd!Example Live Demopackage main import (    "fmt" ) func check(n int) bool{    if n < 2 {       return n % 2 == 0    }    return check(n - 2) } ... Read More

Use Chmod Recursively on Linux

Mukul Latiyan
Updated on 02-Aug-2021 06:45:04

472 Views

You might have been in a scenario where you are using a Linux as your main operating system and then you try to create or edit a file and the Linux terminal responds with something like “Permission deny” error. In typical sense, such an error is related to insufficient permissions that your current user is having and can be solved by setting the correct file permissions or changing the owner.In Linux, the files are controlled through the file permissions, ownership and attributes, which in turn makes sure that only authorized users and processes can access files and directories.Before understanding how ... Read More

Introduction to Arduino Time Library

Yash Sanghvi
Updated on 02-Aug-2021 06:40:33

10K+ Views

The Time library provides you with timekeeping functionality on the Arduino. The latest version of the library is documented here.To install it, search for Time in the Library Manager and install the library by Michael Margolis.You’ll have to scroll a bit to find this library.Once the library is installed, if you go to File → Examples → Time, you will be able to see several examples of integrating this library with various sources: GPS, NTP, RTC, etc.The basic idea is that you can set time using the functions −setTime(hours, minutes, seconds, days, months, years);OR, setTime(t);where t is the special time_t ... Read More

Browse Arduino Libraries by Category on Arduino Website

Yash Sanghvi
Updated on 02-Aug-2021 06:36:54

226 Views

Follow the steps given below to browse Arduino libraries by category on Arduino website −Go to http://arduino.cc/Click Documentation → ReferenceClick Libraries from the left menu.The libraries can now be found in the categorized form on this pageClick the category of your interest and explore the available libraries.

Goto in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 06:34:22

7K+ Views

goto is a control structure in Arduino, like in C, and it is used to transfer the program flow to another point in the program. It is highly discouraged, as many programmers agree that you can write every algorithm you want without the use of goto.Excessive use of goto makes it very difficult to debug programs, or, in some cases, creates program flows which are impossible to debug. It is assumed that you will read further only if you absolutely have to use goto.SyntaxThe syntax for using goto is −goto label; label:    //statementsExampleThe following example demonstrates this −void ... Read More

Reference and Dereference Operator in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 06:32:39

2K+ Views

The reference (&) and dereference operators (*) in Arduino are similar to C. Referencing and dereferencing are used with pointers.If x is a variable, then its address is represented by &x.Similarly, if p is a pointer, then the value contained in the address pointed to by p is represented by &p.Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int x = 10;    int *p;    p = &x; //p now contains the address of x    Serial.print("The value stored in the address pointed by p is: ");Serial.println(*p); } ... Read More

Read Two Numbers and Print Their Quotient and Remainder in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 06:06:15

365 Views

To print the Quotient and Remainder of two numbers, we can use the division operator and the modulo operator.Let's take an Example:a = 15 and b = 2Quotient is 15/2 = 7Remainder is 15 % 2 = 1StepsDefine the variables, a and b.Use print statement for the first number.Use print statement for the second number.Find the division of the numbers, a and b.Find the remainder of the numbers, a and b.Print the calculated division.Print the calculated remainder.Example Live Demopackage main import "fmt" func main(){    var a, b int    fmt.Print("Enter first number: ")    fmt.Scanf("%d", &a)    fmt.Print("Enter second number: ... Read More

Print All Numbers in a Range Divisible by a Given Number in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 06:03:22

511 Views

Let's assume the lower and upper limit for the range is 2 and 10, respectively, and the given number is 2.Iterate in the range of 2 to 10 and find modulo of 2 and print them.StepsDefine variables for upper and lower limit for the range.Print statement for upper and lower limit.Take input from the user.Define a variable (n) to check the divisibility in a range.Take the input from users for n.Iterate in the range of lowerLimit and upperLimit.Find modulo with n in the range and print them.Example Live Demopackage main import "fmt" func main(){    var upperLimit, lowerLimit int    fmt.Printf("Enter ... Read More

Golang Combinations Generator

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 05:36:35

578 Views

Numbers are: a, b and c => 1, 2, 3Combination of (a, b, c) are: (1, 1, 1), (1, 2, 1), (1, 2, 2), (1, 2, 3), . . ., (3, 3, 3).StepsDefine the variables, a, b and c.Print statement for the first number and scan the number.Print statement for the second number and scan the number.Print statement for the third number and scan the number.Initialize an array with numbers, a, b and c.Iterate the array with iterator i, j and k.Print (i, j, k)th index number of the array.Example Live Demopackage main import "fmt" func main(){    var a, b, ... Read More

Deep Sleep in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 05:28:49

8K+ Views

The equivalent of deep sleep in Arduino would be the Power Down mode, which consumes the least power out of all the sleep modes. While this has already been covered in another article, but for the sake of completeness, here’s a brief on the sleep modes in Arduino.Arduino’s microcontroller, ATmega328P has 6 sleep modes, of which 5 are available with the avr/sleep.h library.Idle modeADC Noise ReductionPower-downPower-saveStandbyExtended StandbyEach mode has different wake-up modes and different power consumption.The Idle mode is easiest to wake up from and the Standby and Power down mode is the most difficult to wake up from (you ... Read More

Advertisements