Düzbucaqlının perimetri#7943

Düzbucaqlının perimetri (Həll təhlili)

və tərəfləri olan bir düzbucağın perimetri 2 * (a + b)-yə bərabərdir.

Alqoritm İmplementasiyası

Düzbucağın tərəflərini oxuyun. Onun perimetrini hesablayın və çap edin.

scanf("%d %d",&a,&b);
p = (a + b) * 2;
printf("%d\n",p);

Alqoritm İmplementasiyası – Sinif

#include <stdio.h>

class Rectangle
{
public:
    int x, y;
    Rectangle(int x, int y) : x(x), y(y) {}

    int Perimeter(void)
    {
        return 2 * (x + y);
    }
};

int x, y;

int main(void)
{
    scanf("%d %d", &x, &y);
    Rectangle a(x, y);
    printf("%d\n", a.Perimeter());
    return 0;
}

Java İmplementasiyası

import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        Scanner con = new Scanner(System.in);
        int x = con.nextInt();
        int y = con.nextInt();
        int p = 2 * (x + y);
        System.out.println(p);
        con.close();
    }
}

Java İmplementasiyası – Sinif

import java.util.*;

class Rectangle
{
    int a, b;

    Rectangle(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int Perimeter()
    {
        return 2 * (a + b);
    }
}

public class Main
{
    public static void main(String[] args) 
    {
        Scanner con = new Scanner(System.in);
        int a = con.nextInt();
        int b = con.nextInt();
        Rectangle r = new Rectangle(a, b);
        System.out.println(r.Perimeter());
        con.close();
    }
}

Java İmplementasiyası – Sinif + MyInteger

import java.util.*;

class MyInteger
{
    private int a;

    MyInteger(int a)
    {
        this.a = a;
    }

    MyInteger Add(MyInteger b)
    {
        return new MyInteger(a + b.a); 
    }

    MyInteger Mult(MyInteger b)
    {
        return new MyInteger(a * b.a); 
    }

    MyInteger Mult(int b)
    {
        return new MyInteger(a * b); 
    }

    public String toString()
    {
        return String.valueOf(a);
    }
}

class Rectangle
{
    MyInteger a, b;

    Rectangle(MyInteger a, MyInteger b)
    {
        this.a = a;
        this.b = b;
    }

    public MyInteger Perimeter()
    {
        return a.Add(b).Mult(2);
    }
}

public class Main
{
    public static void main(String[] args) 
    {
        Scanner con = new Scanner(System.in);
        MyInteger a = new MyInteger(con.nextInt());
        MyInteger b = new MyInteger(con.nextInt());
        Rectangle Rect = new Rectangle(a, b);
        System.out.println(Rect.Perimeter());
        con.close();
    }
}