Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EXERCISE 3 The counter in a for or while loop can be given explicit increment: f

ID: 3419608 • Letter: E

Question

EXERCISE 3 The counter in a for or while loop can be given explicit increment: for i -m:k:n to advance the counter i by k each time. In this problem we will evaluate the product of the first 10 odd numbers 19 in two ways: (a) Write a script file that evaluates the product of the first 10 odd numbers using a for loop. (b) Evaluate the product of the first 10 odd numbers using a single MATLAB command. Use the MATLAB command prod. while loop The while loop repeats a sequence of commands as long as some condition is met. The basic structure of a while loop is the following: while

Explanation / Answer

Excercise - 3 Solution

a) Using a script file for multiplying first 10 odd integers

#include<stdio.h>

int main()

{

int Sum=1;

int i;

for(i=1;i<=19;i=i+2)

{

Sum = Sum * i;

}

printf("%d ", Sum);

return 0

}

b) In matlab you can use the inbulit product command by first defining the vector

A = [1:3:5:7:9:11:13:15:17:19]

B = prod(A)

B will contain the multiplication of all the numbers

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote