Program 4: (CozaLozaWoza): Write a program called CozaLozaWoza which prints the
ID: 3804667 • Letter: P
Question
Program 4: (CozaLozaWoza): Write a program called CozaLozaWoza which prints the numbers 1 to 110, 11 numbers per line. The program shall print "Coza" in place of the numbers which are multiples of 3, "Loza" for multiples of 5, "Woza" for multiples of 7, "CozaLoza" for multiples of 3 and 5, and so on. The output shall look like:
1 2 Coza 4 Loza Coza Woza 8 Coza Loza 11
Coza 13 Woza CozaLoza 16 17 Coza 19 Loza CozaWoza 22
23 Coza Loza 26 Coza Woza 29 CozaLoza 31 32 Coza
......
Hint: You should use loops and conditionals
PLEASE I WANT THIS PROGRAM TO BE WRITTEN IN MATLAB SO THAT IT WILL RUN CORRECTLY .
PLEASE I NEED AN ANSWER THAT NO ONE ELSE HAS WRITTEN.
Explanation / Answer
for i=1:10 %number of rows
for j=1:11 %number of columns
number = (i-1)*11 + j; %generate the number
if mod(number,3)==0 || mod(number,5)==0 || mod(number,7)==0 %see if the number is special
if mod(number,3)==0 %print special word for the word
fprintf('Coza');
end
if mod(number,5)==0
fprintf('Loza');
end
if mod(number,7)==0
fprintf('Woza');
end
else
fprintf('%d',number); %print number if number is not divisible by 3 or 5 or 7
end
fprintf(' '); %print blank space after each number
end
fprintf(' '); %print new line after each row
end
I have commented the code for simplicity, but if you still face problems, please comment in the comment section. I hope that you like the answer :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.