Let's suppose the number is: 4Then, the Summation Patten would be:1 = 11 + 2 = 31 + 2 + 3 = 61 + 2 + 3 + 4 = 10StepsTake a value from the user and store it in a variable, n.Use two for loops where the value of t ranges between the values of 1 and n and the value of i ranges between 1 and t.Print the value of i and '+' operator.Find the sum of elements in the list.Print '=' followed by the total sum.Exit.Example Live Demopackage main import "fmt" func main(){ var n int fmt.Print("Enter number: ") fmt.Scanf("%d", &n) for t:=1; t
StepsTake a value from the user and store it in a variable (n).Use a for loop where the value of i ranges between the values of 1 and n.Print the value of i and '+' operator.Find the sum of elements in the list.Print '=' followed by the total sum.Exit.ExplanationUser must first enter the value and store it in a variable, n.The for loop enables i to range between 1 and n (as n+1 is not included).For each iteration, the value of i is printed.'+' operator is printed only if iExample Live Demopackage main import "fmt" func main(){ var n int ... Read More
Let's assume the range is from 0 to 50. We have to print all the integers that aren't divisible by either 2 or 3.StepsUse a for loop ranging from 0 to 50.Then, use an if statement to check if the number isn't divisible by both 2 and 3.Print the numbers satisfying the condition.ExplanationThe for loop ranges from 0 to 50.The number is divided by 2 and 3.If the remainder ≠ 0, the number isn't divisible by either 2 and 3.The number satisfying the condition is printed.Example Live Demopackage main import "fmt" func main(){ for i:=1; i
Suppose the number is: 123456Count of digits in the given number is: 6To count the number of digits in a number, we can take followingStepsTake the value of the integer and store in a variable.Using a while loop, get each digit of the number and increment the count each time a digit is obtained.Print the number of digits in the given integer.Example Live Demopackage main import "fmt" func main(){ var n int fmt.Print("Enter the number: ") fmt.Scanf("%d", &n) count := 0 for n >0 { n = n/10 count++ ... Read More
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP