Compare commits
3 Commits
d29adf8d32
...
990e803a14
Author | SHA1 | Date | |
---|---|---|---|
990e803a14 | |||
17bd180803 | |||
a63625798e |
@ -1,7 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"gowinter/internal"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Welcome to rise field!!!")
|
fmt.Println("Welcome to rise field!!")
|
||||||
|
internal.Run()
|
||||||
}
|
}
|
||||||
|
19
cmd/test.cpp
19
cmd/test.cpp
@ -1,19 +0,0 @@
|
|||||||
// C++ Code to demonstrate getppid()
|
|
||||||
#include <iostream>
|
|
||||||
#include <unistd.h>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// Driver Code
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
pid = fork();
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
cout << "\nParent Process id : "
|
|
||||||
<< getpid() << endl;
|
|
||||||
cout << "\nChild Process with parent id : "
|
|
||||||
<< getppid() << endl;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
16
internal/example.go
Normal file
16
internal/example.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Add(a, b int) {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
fmt.Println("Sum =", a+b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sub(a, b int) {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
fmt.Println("Sub =", a-b)
|
||||||
|
}
|
59
internal/simple_caluculator.go
Normal file
59
internal/simple_caluculator.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var operators []string = []string{"+", "-", "*", "/"}
|
||||||
|
|
||||||
|
func Run() {
|
||||||
|
var x, y int
|
||||||
|
var operator string
|
||||||
|
|
||||||
|
fmt.Println("Введите первое число")
|
||||||
|
_, err := fmt.Scan(&x)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Некорректное число.\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("Введите операцию (+,-,*,/)")
|
||||||
|
fmt.Scan(&operator)
|
||||||
|
if !isExistOperato(operator) {
|
||||||
|
fmt.Printf("Некоректная операция.\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("Введите второе число")
|
||||||
|
_, err = fmt.Scan(&y)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Некорректное число.\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
calculate(x, y, operator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isExistOperato(operatop string) bool {
|
||||||
|
for _, op := range operators {
|
||||||
|
if op == operatop {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculate(x, y int, oprator string) {
|
||||||
|
|
||||||
|
switch oprator {
|
||||||
|
case "+":
|
||||||
|
fmt.Printf("%d + %d = %d\n", x, y, x+y)
|
||||||
|
case "-":
|
||||||
|
fmt.Printf("%d - %d = %d\n", x, y, x-y)
|
||||||
|
case "*":
|
||||||
|
fmt.Printf("%d * %d = %d\n", x, y, x*y)
|
||||||
|
case "/":
|
||||||
|
if y == 0 {
|
||||||
|
fmt.Println("Ошибка: деление на 0 невозможно")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%d + %d = %f\n", x, y, float64(x)/float64(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user