In what language? Most languages have iterator functions like map in JavaScript that will loop through the elements, making this almost a one liner
sum = 0
arr.map( elem => sum += elem )
It's geared towards system administration but would also be useful for devops.
Answer:
The algorithm is as follows:
1. Input sentence
2. Input character
3. Length = len(sentence)
4. count = 0
5. For i = 0 to Length-1
5.1 If sentence[i] == character
5.1.1 count++
6. Print count
7. Stop
The program in C++ is as follows:
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char str[100]; char chr;
cin.getline(str, 100);
cin>>chr;
int count = 0;
for (int i=0;i<strlen(str);i++){
if (str[i] == chr){
count++;} }
cout << count;
return 0;}
Explanation:
I will provide explanation for the c++ program. The explanation can also be extended to the algorithm
This declares the string and the character
char str[100]; char chr;
This gets input for the string variable
cin.getline(str, 100);
This gets input for the character variable
cin>>chr;
This initializes count to 0
int count = 0;
This iterates through the characters of the string
for (int i=0;i<strlen(str);i++){
If the current character equals the search character, count is incremented by 1
if (str[i] == chr){ count++;} }
This prints the count
cout << count;
Answer:
a. In cell A6, enter a formula without using a function that references cell A6 in the Washington worksheet.
b. Copy the formula from cell A6 to the range A7:A9 without copying the formatting.
Explanation:
Microsoft Excel is a spreadsheet application used for data analysis and statistical calculation. The worksheet is made of columns and rows like a table and labeled alphabetically and numerically respectively. Several worksheets can be referenced in an excel workbook
To consolidate data in excel, reference a cell from another worksheet in the formula of the current worksheet and copy the formula from the cell to a given range of cells, without copying the formatting of the cell.
You want to throw 2 dice and get (or show?) their value.
Their value is random, so you need to generate two numbers between 1 & 6.
You may need to display the numbers
The main part of the program needs to know the numbers to limit what the user may do next.
That's most of the first level of decomposition. You need to keep decomposing (breaking into smaller simpler pieces) (think of an outline) and deciding what objects, functions, data structures and logic you're going to use to code this.