Cvika 4
unknown
matlab
a year ago
2.1 kB
3
Indexable
Never
clc clear % 1 % for i = 1:5 % disp(i + "-Matlab") % end % 2 % number = input("Zadajte cislo "); % % for i = 1:number % disp("Tauko " + i); % end % 3 % even = 0; % odd = 0; % % sumEven = 0; % sumOdd = 0; % % for i = 0:20 % random = randi([0, 100]); % % if mod(random, 2) == 0 % even = even + 1; % sumEven = sumEven + random; % % else % odd = odd + 1; % sumOdd = sumOdd + random; % end % end % % disp("Sucet parnych cisel " + sumEven + " ich poceet = " + even); % disp("Sucet neparnych cisel " + sumOdd + " ich poceet = " + odd); % 4 % max = 0; % min = 0; % sum = 0; % avg = 0; % length = 0; % % for i = 1:10 % random = randi([30, 60]); % % sum = sum + random; % length = length + 1; % % if random < min || min == 0 % min = random; % end % % if random > max % max = random; % end % end % % disp("Max " + max); % disp("Min " + min); % disp("Sucet " + sum); % disp("Priemer " + (sum / length)); % 5 % found8 = false; % found16 = false; % % rounds = 0; % % for i = 1:40 % num = randi([8, 16]); % rounds = rounds + 1; % % if num == 8 % found8 = true; % end % % if num == 16 % found16 = true; % end % % if found8 && found16 % break; % end % end % % if found8 && found16 % disp("Cisla 8 a 16 sa nasli v " + rounds + " cykloch"); % else % disp("Cisla 8 a 16 sa nenasli"); % end % 6 % graterThan46 = 0; % % for i = 1:50 % num = randi([0, 100]); % % if num > 46 % continue; % end % % graterThan46 = graterThan46 + 1; % end % % disp(graterThan46); % 7 % occurance5 = 0; % sum4 = 0; % % while true % if occurance5 >= 2 % break; % end % % num = randi([0, 10]); % % if num == 5 % occurance5 = occurance5 + 1; % end % % if num >= 4 % sum4 = sum4 + num; % end % end % % disp(sum4); % 8 % num = input("Zadajte cislo "); % sum = 0; % % numStr = num2str(num); % % for i = 1:length(numStr) % sum = sum + str2num(numStr(i)); % end % % disp(sum); % 9 % 10 % 11