save
All checks were successful
Test Go Action / use-go-action (push) Successful in 7s

This commit is contained in:
Ivan Titov 2025-02-10 21:43:38 +03:00
parent 17bd180803
commit 990e803a14
5 changed files with 80 additions and 20 deletions

BIN
cmd/a.out

Binary file not shown.

View File

@ -1,7 +1,11 @@
package main
import "fmt"
import (
"fmt"
"gowinter/internal"
)
func main() {
fmt.Println("Welcome to rise field!!")
internal.Run()
}

View File

@ -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
View 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)
}

View 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))
}
}