Programerat / programerat.github.io

MIT License
2 stars 0 forks source link

Gjej prodhimin e dy numrave. - Programerat #20

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Gjej prodhimin e dy numrave. - Programerat

https://programerat.github.io/detyrat/problemi-prodhimi-i-numrave-ne-vektor

gurillaz commented 2 years ago
function zgjidhja(array $vektori): int
    {

        $result = null;

        for ($i = 0; $i < count($vektori) - 1; $i++) {

            $temp_prod = $vektori[$i] * $vektori[$i + 1];

            if (is_null($result) || $temp_prod > $result) {
                $result = $temp_prod;
            }
        }

        return $result;
    }
fatonakiki commented 2 years ago
#python
def product(a):
    max=0
    for i in range(len(a)-1):
        prd = a[i]*a[i+1]
        if prd > max:
            max=prd
    return max
didslm commented 2 years ago

@fatonakiki shum bukur. Nje sygjerim: Për shkak që e ke deklaruar max=0, do të thotë që nëse produkti më i madh është numër negativ, kjo logjikë do të kthej zero. Provo me konsideru ni vektor si ky [-23, 4, -3, 8, -12].

fatonakiki commented 2 years ago

@Diarselimi faleminderit per verejtjen!

def product(a):
    max=a[0]*a[1]
    for i in range(len(a)-1):
        prd = a[i]*a[i+1]
        if prd > max:
            max=prd
    return max