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
Leviafan [203]
3 years ago
8

Write a small program that asks the user how many asterisks it should print out. The user responds with a number, then the progr

am prints that number of asterisks.

Computers and Technology
1 answer:
stich3 [128]3 years ago
7 0

Answer:

I am writing a C++ program. Let me know if you want the program in some other programming language.

#include <iostream> //to use input output functions

using namespace std; // to identify objects like cin cout

int main(){  //start of main() function body

int n; // number of asterisks

cout<<"how many asterisks do you want to print? "; //asks user how many asterisks it should print

   cin>>n; // reads the value of number of asterisks that user want to print

   for( int i=0; i< n; i++)    { //loop to display the number of asterisks in output

       printf("*");    } } // print * asterisks

Explanation:

I will explain how the for loop works.

Suppose the user entered 3 as number of asterisks that user wants to print.

So n=3

Now for loop has a variable i that is initialized to 0. For loop checks if the value of i is less than that of n. It is true because i=0 and n=3 and 0<3. So the body of the loop executes. This prints the first asterisk *

Then the value of i is incremented to 1 and becomes i=1

At next iteration loop again checks if value of i is less than n. It is true because i=1 and n=3 and 1<3. So the body of the loop executes. This prints the second asterisk **

Then the value of i is incremented to 1 and becomes i=2

At next iteration loop again checks if value of i is less than n. It is true because i=2 and n=3 and 2<3. So the body of the loop executes. This prints the third asterisk ***

Then the value of i is incremented to 1 and becomes i=3

At next iteration loop again checks if value of i is less than n. This time it evaluates to false because i=3 and n=3 so 3=3. So the loop ends and the output is

***

The output screenshot is attached.

You might be interested in
Define a data type for representing complex numbers. (A complex number consists of 'real' and 'imaginary' parts. The real and im
qwelly [4]

Answer:

A complex data type can be created by the use of class or structures.

#include <iostream>

using namespace std;

class complex{//creating a class complex to store a complex value.

public://defining all the values public.

int real;

int img;

complex(int real,int img)//parameterized constructor.

{

    this->real=real;

    this->img=img;

}

};

int main() {

   complex n1(1,2);//n1 is a complex number with real part 1 and imaginary part 2.

   cout<<n1.real<<" i"<<n1.img<<endl;

return 0;

}

Output

1 i2

Explanation:

I have created a class complex to store complex number with two integer parts real and imaginary.You can also declare them float if you wan to store decimal values and after that i have created a parameterized constructor with real and imaginary values.So we can assign the values at the time of declaration of the object of class complex.

5 0
3 years ago
What should you adjust to make your hard hat fit properly?
schepotkina [342]
You should adjust the headband to make your hard hat fit properly.
5 0
3 years ago
What Will Social Media Look Like in the Future?
Nutka1998 [239]

Answer: Social Media has come long way from just being a platform for interaction to necessity entity. In today's era social media plays a vital part and it can be stated that it'll continue to have the same effect in the future. From being a platform for business organizations to endorse their product and services to a wider audience, to being a platform for an individual to connect to his/her friend and family that live all the way on the other end of the world.

There are several possibilities that Social Media can unlock in the possible future.

3 0
4 years ago
Why is the Physical Link at Layer 1 of the OSI?
nata0808 [166]
Data is checked to make sure it is complete

<span>Layer 1, provides physical connections for transmission and performs the electrical encoding of data. This layer transforms bits to electrical signals.
The lowest, or first, layer of the OSI model. Protocols in the physical layer generate and detect signals so as to transmit and receive data over a network medium. These protocols also set the data transmission rate and monitor data error rates, but do not provide error correction.</span>


3 0
4 years ago
When you take action independent of direct instruction, you are showing _____. power power insubordination insubordination coura
Anarel [89]

Leadership qualities are the traits that define a person's ability to guide and organize. Independent action without any direct instruction is called initiative.

<h3>What is an initiative?</h3>

An initiative is an act of performing and executing the task independent of any instruction or guidance from someone. It is based on self-motivation rather than following commands given by others.

Insubordination is a refusal or disobedience in obeying any command, power is the ability to have an influential behavior and courage means bravery to do something without fear.

Therefore, independent actions without instructions are option D. initiative.

Learn more about the initiative here:

brainly.com/question/21106998

#SPJ1

8 0
2 years ago
Other questions:
  • What were the advantages and disadvantages of agricultural technology to us.
    12·2 answers
  • Justine was interested in learning how to play the piano. Before she was allowed to even play the piano, she has had to learn
    15·2 answers
  • What is a command-line program?
    8·2 answers
  • Text and graphics that have been out of copied are stored in area called the _____
    15·2 answers
  • I make a budget of my 1st Gamer PC its good?
    9·1 answer
  • Which statement gives an advantage of multicellular organisms?
    7·2 answers
  • Wiliam would like to sort a list of items after the data is already entered
    7·2 answers
  • What is it called when a additional document is added to an email
    13·2 answers
  • Your office printer was working earlier in the day but is no longer printing any documents. Pre-existing workstations are manual
    9·1 answer
  • Anil needs to show the overlap of people who live in a certain neighborhood in his city and who support a specific political can
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!