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
Wewaii [24]
4 years ago
13

What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fi

x it? int product = 1; int max = 20; for (int i = 0; i <= max; i++) product = product * i; System.out.println("The product is " + product);
Computers and Technology
1 answer:
postnew [5]4 years ago
8 0

Answer:

0

Explanation:

Given the code segment:

  1.        int product = 1;
  2.        int max = 20;
  3.        for (int i = 0; i <= max; i++)
  4.            product = product * i;
  5.        System.out.println("The product is " + product);

Since the counter i in the for loop started with 0, and therefore <em>product * i </em>will always be 0 no matter how many rounds of loop to go through.

The code is likely to perform factorial calculation. To do so, we need to change the starting value for the counter i to 1.

  1.        int product = 1;
  2.        int max = 20;
  3.        for (int i = 1; i <= max; i++)
  4.            product = product * i;
  5.        System.out.println("The product is " + product);

You might be interested in
Select three advantages of cloud computing.
777dan777 [17]

Answer:

easily managed, large amount of storage capacity, great flexibility

Explanation:

5 0
3 years ago
Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog
Nostrana [21]

Answer:

Check the explanation

Explanation:

Code to copy:

// ConsoleApplication7.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

#include <cstring>

#include <string>

using namespace std;

int * letterFrequency(char s[]);

int main()

{

  int *freq_letters;

  char *s = new char[100];

  freq_letters = new int[26];

  //To read the input string in order to find the frequency of each letter

  cout << "Enter a string: ";

  cin.getline(s, ' ');

  //call the function to find the occurrence of each alphabet

  freq_letters = letterFrequency(s);

  //Display the count

  cout << "Letter Frequency " << endl;

  for (int i = 0; i < 26; i++)

  {

      //Constriant to check if the letter appeared at least once in the string and so printing the frequency of its occurence

      if (freq_letters[i] != 0)

      cout << " " << static_cast<char>(i + 'a') << " " << freq_letters[i] << endl;

  }

  system("pause");

  return 0;

}

//Define the function to find occurrence of each letter in the input string

int * letterFrequency(char s[])

{

  int *occurrence_array;

//to store the output of occurrences for each alphabet

  occurrence_array = new int[26];

// to store the count of occurrence for each letter temporarily

  int letter_count;

  // for loop to check the occurrence for all 26 alphabets

 

  for (int i = 0; i < 26; i++)

  {

      letter_count = 0;

      for (int j = 0; j < strlen(s); j++)

      {

          /*comparing the ascii values of each alphabet with every character from the string by converting it to lower case i.e. case insensitive*/

          if (int('a') + i == int(tolower(s[j])))

              letter_count++;

      }

      occurrence_array[i] = letter_count;//To store the count calculated for each alphabet

  }

  return occurrence_array;

}

The following below code screenshot and output shows that when the string is entered, the output will shows each lettercount irrespective of whether the letter is in capitals or small and does not count non-letter characters (i.e spaces, punctuations etc.)

6 0
3 years ago
What is the output of adding 1001011 and 100000?
Otrada [13]
1101011, 0x6B or 0153
7 0
3 years ago
6. Why did he choose to install the window not totally plumb?
Dmitriy789 [7]

Answer:

Because then it would break

Explanation:

You achieve this by obtaining correct measurements. When measuring a window, plumb refers to the vertical planes, and level refers to the horizontal planes. So he did not install the window totally plumb

8 0
3 years ago
Heelo how do u do python syntax lesson 11 on code academy
pochemuha

have you tried www.khanacademy.org 


3 0
3 years ago
Other questions:
  • Devices such as monitors and printers that are connected to a computer are called ________.
    12·1 answer
  • According to the family life course development framework, the __________ stage of the family life cycle comes to an end with th
    7·1 answer
  • _________ are represented using diamonds linked withparticipant ETs
    6·1 answer
  • 50 points!!!!!
    9·2 answers
  • On most desktop computers, most of the USB ports are on the back of the computer case. Generally, you'll want to connect your mo
    13·1 answer
  • Public-key cryptography can be used for encryption (ElGamal for instance) and key exchange. Furthermore, it has some properties
    9·2 answers
  • You might have trouble interpreting a message if:
    15·1 answer
  • Define the following term. data, database, DBMS, database system, data- base catalog, program-data independence, user wen', DBA,
    12·1 answer
  • Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme
    15·1 answer
  • Write an application named Perfect that displays every perfect number from 1 through 10,000. A number is perfect if it equals th
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!