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
Crazy boy [7]
3 years ago
14

Write a program that asks the user to enter the size of a triangle (an integer from 1 to 50). Display the triangle by writing li

nes of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user. On the next line write one fewer asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only one asterisk is printed.
Computers and Technology
1 answer:
lianna [129]3 years ago
7 0

Answer:

/*

* Program to print traingle using asterisk.

*/

#include<iostream>

using  namespace std;

//Function to print n asterisk in a row.

void printAsterisk(int n)

{

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

   cout<<"*";

}

int main()

{

//Variable to store size of trianle

int size;

cout<<"Enter the size of triangle"<<endl;

cin>>size;

//print asterik in increasing order line by line.

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

{

    printAsterisk(i);

    cout<<endl;

}

//print asterik in decresing order line by line.

for(int i =size-1; i>0;i--)

{

    printAsterisk(i-1);

    cout<<endl;

}

 

 

}

Output:

Enter the size of triangle

10

*

**

***

****

*****

******

*******

********

*********

********

*******

******

*****

****

***

**

*

Explanation:

Since no programming language is mentioned therefore answer is provided in C++.

The above program will use two for loops to print the triangle using asterisk.

The first loop will print the asterisk line by line with each line having one more asterisk than the previous one till the size of the triangle.

The second for loop will print the asterisk using same logic as above but in reverse order.

Final output of triangle will be obtained.

You might be interested in
If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
Nimfa-mama [501]

Answer:  

For 32 bits Instruction Format:

OPCODE   DR               SR1                   SR2      Unused bits

a) Minimum number of bits required to represent the OPCODE = 3 bits

There are 8 opcodes. Patterns required for these opcodes must be unique. For this purpose, take log base 2 of 8 and then ceil the result.

Ceil (log2 (8)) = 3

b) Minimum number of bits For Destination Register(DR) = 4 bits

There are 10 registers. For unique register values take log base 2 of 10 and then ceil the value.  4 bits are required for each register. Hence, DR, SR1 and SR2 all require 12 bits in all.  

Ceil (log2 (10)) = 4

c) Maximum number of UNUSED bits in Instruction encoding = 17 bits

Total number of bits used = bits used for registers + bits used for OPCODE  

     = 12 + 3 = 15  

Total  number of bits for instruction format = 32  

Maximum  No. of Unused bits = 32 – 15 = 17 bits  

OPCODE                DR              SR1             SR2              Unused bits

  3 bits              4 bits          4 bits           4 bits                17 bits

7 0
3 years ago
The following statement calls a function named half, which returns a value that is half
nadezda [96]

Answer:

function half(number) {

     let result = number/2;

     return result;

}

Explanation:

4 0
3 years ago
In the ____ letter style, all components of the letter begin flush with the left margin.
Sedaia [141]
In the block <span>letter style, all components of the letter begin flush with the left margin.</span>
4 0
3 years ago
Hello safiya77 this is for you
Ray Of Light [21]
Hello astropiggy!
Feel free to ask any question!
I’ll try my best to answer them!
5 0
2 years ago
A company's loss control department identifies theft as a recurring loss type over the past year. Based on the department's repo
maria [59]

Answer: C) Motion detectors

Explanation:

Motion detectors is the device that is used for detection of moving object in any area. They are used for security purposes by tracking motion or people and alerting the user.It consist of motion sensor for detection of motion and alerting the users or organization about security breach through alarming .

  • According to the question,Chief information officer should implement motion detectors to investigate about theft that takes place in company's department on regular basis.Any intervention for company's loss will be alerted through tracking motion of the thief.
  • Other options are incorrect because camera is used for recording videos and images. Bio-metric device is used for digital identification of any person to enter into a system. Man-trap is vestibule used for controlling access of a person for security.
  • Thus, the correct option is option(C).
6 0
3 years ago
Other questions:
  • Henry uploaded the photos of his birthday to a cloud storage system. He feels that it’s a safe option for data storage. His frie
    12·1 answer
  • The Spinning Jenny reduced the number of workers necessary to _______. a.remove cotton seeds from fibers b.pump water from the m
    7·1 answer
  • My computer have black spots and line
    7·2 answers
  • Describe network in terms of the class computer lab
    9·1 answer
  • Name the different type of vegetation found in India ?​
    8·2 answers
  • Which tasks can be completed using the Chart Tools Design tab? Check all that apply.
    9·1 answer
  • The first few lines of a script that say "using" ... that point the code to the right groups are called
    11·1 answer
  • Write a program called array1.cpp file that use either regular for loop or range based for loop to display the contents of the a
    14·1 answer
  • Overnight Delivery Service delivers a package to Pam. At the request of Overnight's delivery person, to acknowledge receipt Pam
    13·1 answer
  • Please complete the following questions. It is important that you use complete sentences and present the questions and answers w
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!