Find Smallest Divisor of an Integer in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 14:58:53

411 Views

Consider that the integer is: 75Divisor of that integer is: 3, 5, 15, ..., 75The smallest divisor is: 3StepsTake an integer from the user.Initialize a variable (res) with that number.Use a for loop where the value of i ranges from 2 to the integer.If the number is divisible by i, compare with res. If res > i, then update res with i.Exit from the loop and print res.Example Live Demopackage main import "fmt" func main(){    var n int    fmt.Print("Enter the number: ")    fmt.Scanf("%d", &n)    res := n    for i:=2; i

Print Odd Numbers Within a Given Range in Golang

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 14:54:30

456 Views

To print odd number in a range, we can take two inputs, a and b, for lower and upper limits.Examplea = 2 and b = 9Numbers between a and b are: 2, 3, 4, 5, 6, 7, 8, 9Odd numbers are: 3, 5, 7, 9StepsDefine two numbers, a and b.Take user inputs for the numbers, a and b.Iterate the number between a and b.Find the modulo of 2, print the number if modulo of 2 of that number is not zero.Example Live Demopackage main import "fmt" func main(){    var a, b int    fmt.Print("Enter lower limit number: ")    fmt.Scanf("%d", ... Read More

Read Marks of Subjects and Display Grade in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 14:32:34

592 Views

Let's enter the marks: 89 56 90 67 99Sum of the marks is: 89+56+90+67+99 => 401Avg. = 401/5 = 80.1The steps are as follows:Define variables for 5 subjects.Enter marks for 5 subjects.Find average of the marks to find grade.Use if else block to print grade.Example Live Demopackage main import "fmt" func main(){    var sub1, sub2, sub3, sub4, sub5 int    fmt.Println("Enter marks of the five subjects:")    fmt.Scanf("%d", &sub1)    fmt.Scanf("%d", &sub2)    fmt.Scanf("%d", &sub3)    fmt.Scanf("%d", &sub4)    fmt.Scanf("%d", &sub5)    avg:=(sub1+sub2+sub3+sub4+sub5)/5    if avg>=90{       print("Grade: A")    }else if avg>=80 && avg=70 && avg=60 && avg

Compute n + nn + nnn in Go

Rishikesh Kumar Rishi
Updated on 31-Jul-2021 14:17:48

344 Views

Let's read a number, n=5Then, nn=55 and then nnn=555res = 5 + 55 + 555 => 615To read a number (n) and compute (n+nn+nnn), we can take the followingStepsDefine a variable, n.Print a statement to get the number, n.Take user input for variable, n.Make an expression for (n + nn + nnn).Convert the expression into numbers.Compute the sum of the expression.Example Live Demopackage main import (    "fmt"    "strconv" ) func main(){    var n int    fmt.Print("Enter value of n: ")    fmt.Scanf("%d", &n)    t1 := fmt.Sprintf("%d", n)    t2 := fmt.Sprintf("+%d%d", n, n)    t3 := fmt.Sprintf("+%d%d%d", ... Read More

Make the Arduino Sleep and Then Wake Up

Yash Sanghvi
Updated on 31-Jul-2021 13:57:47

3K+ Views

In this article, we will, as the title suggests, make the Arduino sleep, and wake it up using an interrupt. Arduino’s microcontroller, ATmega328P has 6 sleep modes, of which 5 are available with the avr/sleep.h library. Each mode has different wake-up modes and different power consumption.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 can only ... Read More

Real Time Clock (RTC) with Arduino

Yash Sanghvi
Updated on 31-Jul-2021 13:48:36

2K+ Views

An RTC module keeps track of time once an initial time input is provided to it. This input can come from several sources (NTP, GPS, etc.). The RTC module usually comes with its own crystal oscillator, and even its own battery, so that the timekeeping continues, even if there is a power disturbance on the Arduino.Circuit Diagram −We will use the DS3231 module. It uses I2C for communication (SDA and SCL lines). The circuit diagram is shown below −As you can see, the Vcc pin of DS3231 is connected to 5V, GND to GND, SDA to A4 (SDA) and SCL ... Read More

Compound Operators in Arduino

Yash Sanghvi
Updated on 31-Jul-2021 13:34:22

527 Views

Compound operators in Arduino work just like in C, and they help save you some writing time, and also reduce the number of lines in your code. As the name seems to suggest, compound operators combine multiple operators.The following table lists the compound operators in Arduino.Assume that a and b are integers having values a = 5 and b = 2 in all the following examples −OperatorDescriptionExampleOutput++Incrementa++a=6--Decrementa--a=4+=Compound Additiona+=ba=7-=Compound subtractiona-=ba=3*=Compound multiplicationa*=ba=10/=Compound divisiona/=ba=2%=Compound remaindera%=ba=1&=Compound bitwise ANDa&=ba=0|=Compound bitwise ORa|=ba=7^=Compound bitwise XORa^=ba=7

Convert Variables from One Type to Another in Arduino

Yash Sanghvi
Updated on 31-Jul-2021 13:32:41

4K+ Views

In order to convert variables from one type to another, you use the CAST operator. The syntax is −(type) var;Where var is the variable to be casted, and type is the new type to which you wish to convert it. For example, if you have a variable of type float, and wish to cast it as an int.ExampleHere’s how you can do it −float f; int i; void setup() {    // put your setup code here, to run once:    f = 5.6;    i = (int) f;    Serial.println(f);    Serial.println(i); } void loop() {   ... Read More

Arduino Uno vs STM32duino Blue Pill

Yash Sanghvi
Updated on 31-Jul-2021 13:29:57

4K+ Views

We will have a comparison of the specifications of Arduino Uno and the STM32 Blue Pill Board.Arduino UnoSTM32duino (Blue Pill)UnoSTM32 Blue PillGeneralDimensions2.08¨ x 0.9¨4¨ x 2.1¨Pricing$20-23$3-5ConnectivityI/O Pins1437PWM Pins615Analog In Pins610Analog Out Pins (DAC)--ComputingProcessorATMega328PSTM32F103C8T6Flash Memory32 kB64 kBSRAM2 kB20 kBEEPROM1 kB-Clock speed16 MHz72 MHzVoltage Level5V3.3VUSB ConnectivityStandard A/B USBMicro-USBCommunicationHardware Serial Ports13SPI SupportYes (1x)Yes (2x)CAN SupportNoYesI2C SupportYes (1x)Yes (2x)Apart from the details mentioned above, please note that STM32duino’s microcontroller is ARM Cortex M3 based. It is one of the most cost-effective boards out there, having better specs than Arduino Uno. It is growing in popularity, and for many, it is their first introduction to ... Read More

Arduino Uno vs Teensy

Yash Sanghvi
Updated on 31-Jul-2021 13:26:47

2K+ Views

We will have a comparison of the specifications of Arduino Uno and the Teensy 3.5 board.Arduino UnoTeensyPlease refer to the table below for the detailed comparison −UnoTeensy3.5GeneralDimensions2.7¨ x 2.1¨2.5¨ x 0.7¨Pricing$20-23$25-28ConnectivityI/O Pins1442PWM Pins620Analog Pins625ComputingProcessorATMega328PMK64FX512VMD12Flash Memory32 kB512 kBSRAM2 kB256 kBEEPROM1 kB4 kBClock speed16 MHz120 MHzVoltage Level5V3.3V (though all pins are 5V tolerant)USB ConnectivityStandard A/B USBMicro-USBCommunicationHardware Serial Ports16SPI SupportYes (1x)Yes (3x)CAN SupportNoYesI2C SupportYes (1x)Yes (3x)Apart from the points mentioned above, as you can see from Teensy 3.5’s visual, it has a builtin SD Card Holder. It also has a Cryptographic Acceleration Unit, Real Time Clock and CRC Computation Unit. Its microcontroller is ... Read More

Advertisements