Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Programming Articles - Page 1149 of 3366
331 Views
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 n-1 and 0 with a decrement of 1 with each iteration.Multiply the empty spaces with n-i and '*' with i and print both of them.Exit.ExplanationUser must first enter the value and store it in a variable, n.The for loop enables i to range between n-1 and 0 with a decrement of 1 with each iteration.For each iteration, " " is multiplied with n-i and '*' is multiplied with i to ensure correct spacing of ... Read More
251 Views
The steps to print an identity matrix using Golang is as follows :Take a value from the user and store it in a variable, n.Use two for loops where the value of j ranges between the values of 0 and n-1 and the value of i also ranges between 0 and n-1.Print the value of 1 when i is equal to j, and 0 otherwise.Case 1:Enter a number: 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1Case 2:Enter a number: 5 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1Example Live Demopackage main import "fmt" func main(){ var n int fmt.Print("Enter a number: ") fmt.Scanf("%d", &n) for i:=0; i
279 Views
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
130 Views
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
387 Views
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
4K+ Views
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
397 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
445 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
567 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
350 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