answer.
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
Stells [14]
2 years ago
15

Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if

the side length is 4, the program should display[a diamond with the middle having 7 asterisks]
*

***

*****

*******

*****

***

*

Computers and Technology
2 answers:
vazorg [7]2 years ago
8 0

Answer:

side = int(input("Please input side length of diamond: "))

# for loop that loop from 0 to n - 1

for i in range(side-1):

   # inside the print statement we determine the number of space to print

   # using n - 1 and repeat the space

   # we also determine the number of asterisk to print on a line

   # using 2 * i + 1

   print((side-i) * ' ' + (2*i+1) * '*')

# for loop that loop from 0 to n - 1 in reversed way

for i in range(side-1, -1, -1):

   # this print statement display the lower half of the diamond

   # it uses the same computation as the first for loop

   print((side-i) * ' ' + (2*i+1) * '*')

Explanation:

The program is written in Python and well commented. The first for loop display the first half of the diamond while the second for loop display the lower half.

A screenshot of program output when the code is executed is attached.

zaharov [31]2 years ago
3 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        int n = input.nextInt();
  6.        int l = 1;
  7.        for(int i=1; i <= n; i++){
  8.            for(int j=1; j<= l; j++){
  9.                System.out.print("*");
  10.            }
  11.            System.out.println();
  12.            l = l + 2;
  13.        }
  14.        l = l - 4;
  15.        for(int i=1; i < n; i++){
  16.            for(int j=1; j <= l; j++){
  17.                System.out.print("*");
  18.            }
  19.            System.out.println();
  20.            l = l-2;
  21.        }
  22.    }
  23. }

Explanation:

The solution code is written in Java.

Firstly use a Scanner object to accept an input integer (Line 5-6).

Create the first set of inner loops to print the upper part of the diamond shape (Line 8-14). The variable l is to set the limit number of asterisk to be printed in each row.

Next, create another inner loops to print the lower part of the diamond shape (Line 17-23). The same variable l is used to set the limit number of asterisk to be printed in each row.

You might be interested in
In your own words, what is pair-programming? What is the role of the driver? What is the role of the navigator? What are some be
KATRIN_1 [288]

<u>Paired programming:</u>

Paired programming is a new technique where one person gets one another to<em> write the code</em>. Here one will write the code and other will start verifying as the type.

So we might think it is waste to employ two person for same task but it is not so. There are many <em>benefits in incorporating this technique</em>. Let us see those benefits one by one.

  • <em>Inter-personal skill gets improved </em>
  • <em>Lower amount of coding mistake </em>
  • <em>Learn from each other </em>
  • <em>Peer review enhance collaboration </em>

Challenges expect to arise during pair-programming

  • Two heads are superior to one. On the off chance that the driver experiences a <em>hitch with the code</em>, there will be two of them who'll take care of the issue.  
  • Builds up your <em>staff's relational aptitudes</em>. Working together on a solitary venture encourages your group to welcome the estimation of <em>correspondence and collaboration.  </em>

Overcome Method

The most ideal approach to move <em>toward blending</em> is to accomplice two software engineers and have them share a PC. The pair ought to have the option to choose how to part the work, and it is prudent that they should <em>switch jobs frequently.</em>

7 0
2 years ago
How do you download a video from sendvid
Leona [35]
You copy the url and paste it in the box on the website

5 0
2 years ago
Read 2 more answers
On a DTP project, Morgan is preparing digital files to be sent to a printer. Which word describes the activity that Morgan is pe
VladimirAG [237]

In this activity Morgan is preparing the digital files to a printer  on a DTP project.

Explanation:

DTP project is the creation of documents using page layout on a personal computer. The process of printing digital based images directly to variety of media substrates is known as digital processing.

The digital files like PDFs can be sent directly to digital printing press to print on paper, photo paper, fabric and so on.

They have unique fade rates and different sensitives to the various deterioration mechanisms. DTP is used for graphic designers to create documents.

6 0
2 years ago
Read 2 more answers
Although the DBMS is designed to recover a database to a previous consistent state when an interruption prevents the completion
Alexandra [31]

Answer:

The answer to the given question is "True".

Explanation:

In the database, we use the queries, when some error has occurred with queries so, the database provides a PL/SQL  that is known as the procedural language that is the combination of the structured query language.  

In this programming language, we use some triggers that are mainly available with database. The triggers are a set of the code that is executed automatically when an interruption has occurred.  

That's why the answer to this question is "True"

3 0
2 years ago
Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input.
Neko [114]

Answer:

In C++:

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

int main(){

   string lname, fname,stringnum;    int num; string login, pwd;

   cout<<"Last Name: ";    cin>>lname;

   cout<<"First Name: ";    cin>>fname;

   cout<<"Four-digit integer: ";    cin>>num;

   stringnum = to_string(num).substr(0,4);

   stringstream geek(stringnum);    geek>>num;

   num = num%100;

   pwd = to_string(num);

   if(lname.length()<5){ login = lname+fname.substr(0,1);    }

   else{ login = lname.substr(0,5)+fname.substr(0,1);    }

   cout<<"Login Name: "<<login<<endl;

   cout<<"Password: "<<pwd<<endl;

   return 0;

}

Explanation:

This declares all necessary variables

   string lname, fname,stringnum;    int num;     string login, pwd;

This prompts the user for last name

   cout<<"Last Name: ";    cin>>lname;

This prompts the user for first name

   cout<<"First Name: ";    cin>>fname;

This prompts the user for a four digit integer

   cout<<"Four-digit integer: ";    cin>>num;

This converts the input number to string and gets only the first four integer

   stringnum = to_string(num).substr(0,4);

This converts the string back to an integer

   stringstream geek(stringnum);    geek>>num;

This gets the last two of the four digit integer

   num = num%100;

This gets the password of the user

  pwd = to_string(num);

This gets the login name of the user.

This is executed if the length of the first name is less than 5

<em>    if(lname.length()<5){ login = lname+fname.substr(0,1);    }</em>

This is executed if otherwise

<em>    else{ login = lname.substr(0,5)+fname.substr(0,1);    }</em>

This prints the login name

   cout<<"Login Name: "<<login<<endl;

This prints the password

   cout<<"Password: "<<pwd<<endl;

3 0
2 years ago
Other questions:
  • Give at least one example computer application for which a connection-oriented service is appropriate and at least one example c
    12·1 answer
  • Which are methods used to improve reading fluency? Check all that apply. Practicing with a weak reader listening to a fluent rea
    5·2 answers
  • If the computer has an encrypted drive, a ____ acquisition is done if the password or passphrase is available. a. passive b. sta
    8·1 answer
  • Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T
    9·1 answer
  • You are on vacation and want to see where all the restaurants and trendy shops are in relation to your hotel. You remember there
    15·1 answer
  • Which of the following statements is true? Using existing exceptions makes the program less robust. Always create your own excep
    15·1 answer
  • System design is the determination of the overall system architecture-consisting of a set of physical processing components, ___
    6·2 answers
  • php Exercise 3: Function Write a function named word_count that accepts a string as its parameter and returns the number of word
    5·1 answer
  • Accenture has partnered with a global construction company that specializes in building skyscrapers. The company wants better ma
    12·1 answer
  • You work at a computer repair store. A customer is having trouble with their hard drives. The computer is not recognizing all th
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!