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 1150 of 3366
486 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
583 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
334 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
1K+ Views
Input array is: [2, 4, 1, 6, 5]Sum = 2 + 4 + 1 + 6 + 5 => 18Average = 18/5 => 3.6 ~ 3To calculate the average of numbers in a given list, we can take following steps −Let's take an input list of numbers.Find the sum of numbers using sum() method.The sum method calculates the sum of numbers by iterating the given list.Print the average by dividing the sum with the length of the given list.Example Live Demopackage main import ( "fmt" ) func sum(arr []int) int{ result := 0 for _, i :=range arr ... Read More
1K+ Views
To create a class that can perform basic calculator operations, we can take following StepsWe can define a Calculator class with two numbers, a and b.Define a member method to calculate the addition of two numbers.Define a member method to calculate the multiplication of two numbers.Define a member method to calculate the division of two numbers.Define a member method to calculate the subtraction of two numbers.In the main method, declare two variables, a and b.Get an instance of Calculator.Initialize a choice variable, based on which mathematical operations could be performed.Example Live Demopackage main import ( "fmt" ) type Calculator struct ... Read More
490 Views
To compute the area and perimeter of a circle, we can take following steps −Define a struct with circle properties such as radius.Define a method to calculate the area of the circle.Define a method to calculate the perimeter of the circle.In the main method, take the user's input for circle's radius.Instantiate the circle with the radius.Print the area of the circle.Print the perimeter of the circle.Example Live Demopackage main import ( "fmt" "math" ) type Circle struct { radius float64 } func (r *Circle)Area() float64{ return math.Pi * r.radius * r.radius } func (r *Circle)Perimeter() float64{ ... Read More
553 Views
To find the area of a rectangle using classes, we can take following StepsDefine a struct with rectangle properties such as breadth and length.Define a method to calculate the area of the rectangle.In the main method, instantiate an object of rectangle.Call the struct method, i.e., Area, to calculate the area of the rectangle.Print the area of the rectangle.Example Live Demopackage main import ( "fmt" ) type Rectangle struct { breadth int len int } func (r *Rectangle)Area() int{ return r. len * r.breadth } func main(){ rectangle := Rectangle{ breadth: 10, ... Read More
1K+ Views
pre.prettyprint{width:99%!important;} a.demo{top:12px!important; float:right!important;}To read the contents of a file, we can take following steps −We can create a file called test.txt.Clean-up using defer statement.Write the contents of string.Call ReadFile() method to read the file.ReadFile reads the file named by filename and returns the contents.Print the content of the file.Example Live Demopackage main import ( "fmt" "io/ioutil" "log" "os" ) func CreateFile() { file, err := os.Create("test.txt") if err != nil { log.Fatalf("failed creating file: %s", err) } defer file.Close() _, err = file.WriteString("Welcome to Tutorials Point") if err ... Read More
5K+ Views
A function is a group of statements that together perform a task. You can divide up your code into separate functions.Functions help in reducing the code redundancy and at the same time they make the code much more readable and less error prone.In Lua, we declare functions with the help of the function keyword and then, we can invoke(call) the functions just by writing a pair of parentheses followed by the functions name.ExampleConsider the example shown below − Live Demofunction add(a, b) -- declaring the function return a + b end result = add(1, 2) -- calling the function print(result) ... Read More
2K+ Views
We can create standalone Lua executables with the help of the third party packages like srlua.srlua does a perfect job in converting a Lua script file into an executable, and we can do it on both the major platforms, whether that is the windows or the Unix based systems.Let’s first learn how to do it on a Windows system.Consider the steps mentioned below as a reference −First, visit the github link of the srlua project. Please click the following link. After that, you need to clone the repository on your local windows machine with this command −git clone https://github.com/LuaDist/srlua.gitIt should ... Read More