1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tema [17]
3 years ago
12

Write programs with loops that compute:

Computers and Technology
1 answer:
Katarina [22]3 years ago
6 0

Answer:

The programs are written in MATLAB.

(a)

sum = 0;

for i = 2:100  %This for loop starts from 2 and ends at 100

   sum = sum + i;  %This line sums each values of the loop

end

disp(sum); %This command displays the sum at command window

(b)

sum = 0;

for i = 2:100

   sum = sum + i^2;  %This line sums the squares of each values in the loop

end

disp(sum);

(c)

sum = 0;

a = input('Please enter a: ');

b = input('Please enter b: ');

for i = a:b

   if mod(i,2) == 1  %This command checks whether the value in the loop is odd or not

       sum = sum + i;  %This command sums each odd value in the loop

   end

end

(d)

seq = input('Please enter a few numbers with square brackets [] around them: ');

small = seq(1);  %Initialize small

large = seq(1);  % Initialize large

for i = 1:length(seq)  %Iterate over the sequence

   if seq(i) < small

       small = seq(i);  %Decide if the value in the loop is smallest

   elseif seq(i) > large

       large = seq(i);  %Decide if the value in the loop is largest

   end

end

fprintf('The smallest of the inputs is %g,\nThe largest of the inputs is %g.\n',small,large);

You might be interested in
How do you access the dark web
Artist 52 [7]

Answer:

look up dark web links

Explanation:

8 0
4 years ago
Read 2 more answers
HELP 11 pointsw to the person who helps me
baherus [9]
I believe it Is 2 and 3
7 0
4 years ago
Read 2 more answers
The name of the unique identifier assigned to a personal computer
My name is Ann [436]
That would be your username example: makastor.pc.home
6 0
4 years ago
The function's only behavior should be to return the sum of array userVals' elements. What common error does the function make?
Leno4ka [110]

Answer:

A. Attempts to access an invalid element.

Explanation:

The C program above is supposed to loops 10 times to get the total of the userVal's element, but the loop is assigning the cumulative sum of the to each nth index of the userVal array. Although the cumulative total of the array is assigned to the last index, the return statement is attempting to return an invalid element (since i is local only to the for loop statement). The program should return the userVal[9] instead.

5 0
3 years ago
How do you stop the beeping noise on your computer?
ad-work [718]
Smash it with a hammer 
3 0
3 years ago
Other questions:
  • Jesse has finished typing an essay for her college assignment and submitted it. The next day she received an email from her prof
    15·2 answers
  • - If we place records from different tables in adjacent____________, it would increase efficiency of a database.
    14·1 answer
  • Henry uses a laptop and has noticed that sometimes when he is typing, the cursor will move, causing him to mistype words or even
    5·1 answer
  • Study the images of two different fronts.
    7·2 answers
  • What are the characteristics of calendar sharing options in Outlook 2016? Check all that apply.
    13·2 answers
  • This code --&gt; plt.plot(x,y) is used to draw :
    8·1 answer
  • Why does it say error on that last line of code
    15·2 answers
  • List and briefly define the four main elements of a computer.​
    9·1 answer
  • A relational database can best be described as a collection of related _____ designed to minimize redundant data.
    5·1 answer
  • The (blank) option will help determine the overall look of her presentation.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!