S

@supriyo_biswas

A tour of Go - Flow Control - For loops

Go
6 years ago
// for is the only looping construct in Go // similar to C/C++/Java/JavaScript with three // expressions. All three can be omitted. package main import "fmt" func main() { for i := 10; i > 0; i-- {

A tour of Go - Basics - Numeric constants

Go
6 years ago
// Go supports high precision values in // numeric constants, and an untyped constant // takes the type needed by its context. // However, when assigned to a variable, or // when operations are performed on it, then // it may have an error. package main import "fmt"

A tour of Go - Basics - Constants

Go
6 years ago
package main import "fmt" func main() { // constants are declared like variables // cannot be declared with the := syntax const Pi = 3.1415926535 const Zero int = 0

A tour of Go - Basics - Type Inference

Go
6 years ago
// when using either ":=" or "var" without a type // type is inferred based on type of the rvalue in // case rvalue is a variable, or the precision // required to represent rvalue in case rvalue is // a constant. package main import "fmt"

A tour of Go - Basics - Type Conversions

Go
6 years ago
// a statement of the type: // T(v) // where T is a type and v is a value converts // v to the type T package main import ( "fmt" "math"

A tour of Go - Basics - Basic Types

Go
6 years ago
// basic types in go: // * bool // * string // * int int8 int16 int32 int64 // * uint uint8 uint16 uint32 uint64 uintptr // * byte (alias for uint8) // * rune (alias for int32, represents Unicode code point) // * float32 float64 // * complex64 complex128

A tour of Go - Basics - Short variable declarations

Go
6 years ago
package main import "fmt" func main() { // inside a function, if a new variable is being // *declared* (excludes variable assignments/reuse) // you can use ":=" instead of "var ... = ..." var i, j int = 1, 2

A tour of Go - Basics - Variables with initializers

Go
6 years ago
package main import "fmt" // Variable names followed by type and then the // list of values var i, j int = 1, 2 func main() { // if type is omitted, will assume the type from

A tour of Go - Basics - Variables

Go
6 years ago
// declaring a list of variables with var // if there is no explicit value given, initialized // to a "zero value". package main import "fmt" var c, python, java bool

A tour of Go - Basics - Named return values

Go
6 years ago
package main import "fmt" // x and y declared in the function body will // be returned. you can still return any variables of // your choice by explicitly mentioning them func split(sum int) (x, y int) { x = sum * 4 / 9

A tour of Go - Basics - Multiple results

Go
6 years ago
package main import "fmt" // functions can return multiple results func swap(x, y string) (string, string) { return y, x } func main() {

A tour of Go - Basics - Functions

Go
6 years ago
package main import "fmt" // types occur at the end func add(x int, y int) int { return x + y } // when a sequence of parameters have the same types

A tour of Go - Basics - Exported names

Go
6 years ago
package main import ( "fmt" "math" ) func main() { // names are exported (i.e. publicly accessible) if // their names begin with a captial letter, e.g. "Pi"

A tour of Go - Basics - Imports

Go
6 years ago
package main // Multiple import statements import "fmt" import "math/rand" import "time" func main() { rand.Seed(time.Now().UTC().UnixNano()) fmt.Println("My favourite number is", rand.Intn(10))

A tour of Go - Basics - Packages

Go
6 years ago
// Package import occurs with import paths, such as "fmt" // or "math/rand". By convention, last element of the import // path and the package name is the same. package main // This is a factored import statement import ( "fmt" "math/rand"

Arrays: Matrix multiplication

C
6 years ago
#include <stdio.h> int main() { // declare input and output arrays int a[10][10], b[10][10], c[10][10]; // declare loop variables and variables to use // to store the number of rows and columns int a_rows, a_cols, b_rows, b_cols, i, j, k;

Array: initializing and using three dimensional arrays

C
6 years ago
#include <stdio.h> int main() { // declare a 3x2x2 3D array with initializer list int a[3][2][2] = { { {10, 20}, {30, 40}, }, {

Arrays: Sum of two matrices

C
6 years ago
#include <stdio.h> int main() { // declare input and output arrays, and variables // for the number of rows and columns. there are // also two loop variables i and j. int a[10][10], b[10][10], sum[10][10], rows, cols, i, j; printf("Enter the number of rows:\n"); scanf("%d", &rows);

Arrays: Transpose of a matrix

C
6 years ago
#include <stdio.h> int main() { // declare input and output array, and variables // for the number of rows and columns. there are // also two loop variables i and j. int a[10][10], b[10][10], rows, cols, i, j; printf("Enter the number of rows:\n"); scanf("%d", &rows);

Arrays: two-dimensional arrays initialization and usage

C
6 years ago
#include <stdio.h> int main() { // declare an array int a[2][2]; // perform a few operations a[0][0] = 10; a[0][1] = a[0][0] * 10; a[1][0] = a[0][1] / 5;