Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ◇C++, ◇Clojure, ◇Scala


[ edit | logout ]
[ sandbox | passwd ]

sum, product, factorial

These are all in the stdlib, in std/math :)

import std/math        # sum, prod, fac


let numbers = @[1, 2, 3, 4, 5]

echo numbers.sum()    # 15

echo numbers.prod()   # 120

echo fac(5)           # 120; 5 * 4 * 3 * 2 * 1

Exercises

Implement these functions by yourself.

  • Write a function that receives a seq of numbers and returns the sum of the elements. The sum of the empty seq is 0.
  • Write a function that receives a seq of numbers and returns the product of the elements. The product of the empty seq is 1.
  • Write a function that calculates the factorial of a number. Implement it in a recursive and non-recursive way too.
  • Try to make your sum and product functions more general. Your functions should accept both static and dynamic arrays. What type should be used on the formal parameter list?
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 01, 22:50