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;
The answer to your Question is false
<span>Ben has to write a note on color concepts. Help him complete the following sentences.
When light hits a surface, the surface absorbs some of the light and reflects the rest. The color that you see depends on which light waves the surface reflects
( reflects, absorbs, emits) the most. You perceive objects as having a specific color because of these constituent ______( rays, colors, intensities) of light.
I wasn't sure on the last one.</span>
Answer:
- init_balance = float(input("Initial balance: "))
- interest = float(input("Annual interest rate in percent: "))
-
- montly_interest = (interest / 100) / 12
- current_amount = init_balance + init_balance * montly_interest
- print("After first month: %.2f " % current_amount)
-
- current_amount = current_amount + current_amount * montly_interest
- print("After second month: %.2f " % current_amount)
-
- current_amount = current_amount + current_amount * montly_interest
- print("After third month: %.2f " % current_amount)
Explanation:
The solution code is written in Python.
Firstly, prompt user to input initial balance and annual interest rate using input function (Line 1 - 2).
Next, divide the annual interest by 100 and then by 12 to get the monthly interest rate (Line 4).
Apply the formula to calculate the current amount after adding the monthly interest (Line 5) and display the current month after first month (Line 6).
Repeat the same steps of Line 5 - 6 to calculate amount after two and three months and display print them to console. (Line 8 - 12).