[Solved] You are given an array consisting of n integers. Print the last two digits of the product of its array values [duplicate]


You can try this (it’s version of Python3):

n = int(input())
arr = list(map(int, input().rstrip().split()))

result = 1
for num in arr:
    result = (result * num) % 100

print("{:02d}".format(result))

A little bit modify for better algorithm:

n = int(input())
arr = list(map(int, input().rstrip().split()))

result = 1
for num in arr:
    result = (result * num) % 100
    if(result==0): break   # 0 multiply by any number still be 0

print("{:02d}".format(result))

solved You are given an array consisting of n integers. Print the last two digits of the product of its array values [duplicate]