Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Homework algorithms

1. Compute the sum of odd numbers from 1 to n.

BEGIN
i=1; n; sum;
WHILE i<n
sum=sum+I;
i=i+2;
ENDWHILE
Print sum;
END

4. Given an array of strings, output the total number (count) of characters in the
list. Example: a = ["ana", "are", "mere"] => count = 10; for a = [] (empty array, with
no elements), count = 0
BEGIN
n; i; count; X[i]length;
i=0; count=0;
WHILE i < n
count=count + X[i]length;
i = i + 1;
EDNWHILE
Print: “ Numarul total de caractere din sir este” + count;
END
3. The minimum number in an array.

BEGIN
X[]; n; i=n-1; min;
min=X[n-1]
WHILE i >=0
IF X[i]<min THAN
min=X[i];
ENDIF
i=i-1;
ENDWHILE
Print: “Elementul minim este” + min;
END

You might also like