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 lines 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 displayed. (Hint: Use nested for loops; the outside loop controls the number of lines to write, and the inside loop controls the number of asterisks to display on a line.) For example, if the user enters 3, the output would be:_______.a. *b. **c. ***d. **e. *

Answers

Answer 1
Answer:

Answer:

Implemented using Python

n = int(input("Sides: "))

if(n>=1 and n <=50):

    for i in range(1,n+1):

         for j in range(1,i+1):

              print('*',end='')

         print("")

       

    for i in range(n,0,-1):

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

              print('*',end='')

         print("")

else:

         print("Range must be within 1 and 50")

Explanation:

This line prompts user for number of sides

n = int(input("Sides: "))

The line validates user input for 1 to 50

if(n>=1 and n <=50):

The following iteration uses nested loop to print * in ascending order

   for i in range(1,n+1):

         for j in range(1,i+1):

              print('*',end='')

         print("")

The following iteration uses nested loop to print * in descending order        

    for i in range(n,0,-1):

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

              print('*',end='')

         print("")

The following is executed if user input is outside 1 and 50

else:

         print("Range must be within 1 and 50")


Related Questions

3. What is the error in the following pseudocode? // The searchName function accepts a string containing the name // to search for, an array of strings containing the names, and // an integer specifying the size of the array. The function // searches for the name in the array. If the name is found, the // string containing the name is returned; otherwise a message // indicating that the name was not found in the array is // returned. Function String searchName(String name, String names[], Integer size) Declare Boolean found Declare Integer index Declare String result // Step through the array searching for the // specified name. While found == False AND index <= size − 1 If contains(names[index], name) Then Set found = True Else Set index = index + 1 End If End While // Determine the result. If found == True Then Set result = names[index] Else Set result = "That name was not found in the array." End If Return result End Function
What decision-making style most likely requires the most amount of data analysis?
In the early days of computer technology, which system was justified because data-processing personnel were in short supply, hardware and software were expensive, and only large organizations could afford computers
Which of the following tools is specifically designed to test the dc voltage on a hard disk drive
Why is color theory important

/* ELEN 1301 Programming Assignment #5. Name : Your name. Student ID : Your student ID #. Due date : Due date Purpose of the program : Finding the average, minimum and maximum values of seven entered numbers. Use iomanip library to show 3 digits below decimal point. Section 1 : Enter the first number. Set min and max variables to the entered number. Section 2 : Enter the next number. If it is smaller than min, replace the min with the entered number. If it is bigger than max, replace the max with the entered number. Section 3 : Repeat section 2 five more times, so that you have seven numbers. Section 4 : Calculate the average of the seven numbers and show the result with 3 digits below decimal point. (2 points) Section 5 : Show the minimum number. (2 points) Section 6 : Show the maximum number. (2 points) */ #include #include using namespace std; int main() { int n1, n2, n3, n4, n5, n6, n7, min, max; double sum = 0; // Write the rest of the program. return 0; } // main

Answers

Answer:

Here is the C++ program:

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

#include<iomanip> //to use setprecision

using namespace std; //to identify objects cin cout

int main() { //start of main function

     int n1, n2, n3, n4, n5, n6, n7, min, max;  // declare variables for 7 numbers, minimum value and maximum value

     double sum= 0; //declare variable to hold sum of 7 numbers

     double average;  //declare variable to hold average of 7 numbers

     cout<<"Enter first number: "; //prompts user to enter 1st number

     cin>>n1; //reads first number from user

     max = n1; //sets the first number to maximum

     min=n1; //sets the first number to minimum

     cout<<"Enter second number: "; //prompts user to enter 2nd number

     cin>>n2; //reads second number from user

     if(n2<min){ //if second number is less than min

          min=n2;      } //sets min to n2

     if(n2>max){ //if n2 is greater than max

          max = n2;      } //sets max to n2

     cout<<"Enter third number: ";  //prompts user to enter 3rd number

     cin>>n3; //reads third number from user

     if(n3<min){ //checks if n3 is greater than min

          min=n3;      } //sets n3 to min

     if(n3>max){ //checks if n3 is greater than max

          max = n3;      }      //sets max to n3

    cout<<"Enter fourth number: ";//prompts user to enter 4th number

     cin>>n4; //reads fourth number from user

     if(n4<min){  //if n4 is less than min

          min=n4;      }  //sets min to n4

     if(n4>max){  //if n4 is greater than max

          max = n4;      }  //sets max to n4

     cout<<"Enter fifth number: "; //prompts user to enter 5th number

     cin>>n5; //reads fifth number from user

     if(n5<min){  //if n5 is less than min

          min=n5;     }  //sets min to n5

     if(n5>max){  //if n5 is greater than max

          max = n5;      }  //sets max to n5

     cout<<"Enter sixth number: "; //prompts user to enter 6th number

     cin>>n6; //reads sixth number from user

     if(n6<min){ // if n6 is less than min

          min=n6;      }  //sets min to n6

     if(n6>max){  //if n6 is greater than max

          max = n6;      }  //sets max to n6

     cout<<"Enter seventh number: ";//prompts user to enter 7th number

     cin>>n7; //reads seventh number from user

     if(n7<min){  //if n7 is less than minimum number

          min=n7;      }  //assigns n7 to min

     if(n7>max){  //if n7 is greater than the maximum number

          max = n7;      }  //assigns n7 to max

     sum = n1+n2+n3+n4+n5+n6+n7;  //adds 7 numbers

     average = sum/7;  //computes average of 7 numbers

     cout<<"The average is: "<<fixed<<setprecision(3)<<average<<endl; //displays average value up to show 3 digits below decimal point using setprecision method of iomanip library

     cout<<"The maximum number is: "<<max<<endl; //displays maximum number of 7 numbers

     cout<<"The minimum number is: "<<min<<endl;  //displays miimum number of 7 numbers    

     return 0; }

Explanation:

The program is well explained in the comments attached to each statement of program. For example if

n1 = 3

n2 = 9

n3 = 7

n4 = 6

n5 = 2

n6 = 5

n7 = 4

When n1 is read using cin then this number is set to max and min as:

min = 9

max = 3

Now when n2 is read, the first if condition checks if n2 is less than min and second if condition checks if n2 is greater than max. As n2 = 9 so it is not less than min so this if condition is false and n2 is greater than max i.e. 3 so this condition is true. So 9 is assigned to max.

min = 9

max = 9

Now when n3 is read the values of min and max become:

min = 7

max = 9

Now when n4 is read the values of min and max become:

min = 6

max = 9

Now when n5 is read the values of min and max become:

min = 2

max = 9

Now when n6 is read the values of min and max become:

min = 2

max = 9

Now when n7 is read the values of min and max become:

min = 2

max = 9

Now the statement       sum = n1+n2+n3+n4+n5+n6+n7;

executes which becomes:

sum = 3 + 9 + 7 + 6 + 2 + 5 + 4

sum = 36.0

Next program control moves to statement:

average = sum/7;

this becomes

average = 36/7

5.142857

Since this is to be displayed up to 3 decimal places so average = 5.143

the complete output of the program is attached.

1. What are the advantages and disadvantages of technology in communication?

Answers

The advantages and the disadvantages of the communication with the used of the technology are: Quickly communicate and the lack of privacy.

What is communication?

The term communication refers to the exchange of thoughts, ideas, and messages that are shared between two or more people. Without language, a person can survive, but without communication, no one can survive. Communication is divided into two categories, such as interpersonal and intrapersonal.

Advantages of the communication with the used of the technology are:

  • Quickly communicate.
  • Easy to used.
  • Managed the data and share the data easily.

Disadvantages of the communication with the used of the technology are:

  • Privacy issues.
  • Hacking Data.
  • They recover the data all the time not to the easy.

Hence, the significance of the communication are the aforementioned.

Learn more about on communication, here:

brainly.com/question/22558440

#SPJ2

Answer:

ADVANTAGES:

First, the evolution of technology is beneficial to humans for several reasons. At the medical level, technology can help treat more sick people and consequently save many lives and combat very harmful viruses and bacteria.

2-Technology has also increased the productivity of almost every industry in the world. Thanks to technology, we can even pay with bitcoins instead of using banks

DISADVANTAGES:

1-Lack of Privacy. You might think that a quick text or IM offers more privacy than a telephone call in a crowded room. ...

2-Distraction from Real Life. ...

3-Potential for Misunderstanding. ...

4-Decline of Grammar and Spelling...

5- Near people are far and far people are near through communication technology. we have no time to sit with our relatives but constantly communicate far away people . I think this is biggest disadvantage

Explanation:

A(n) _____ of an class is where the services or behaviors of the class is defined. (Points : 6) operationattribute
class
object
abstract class

Answers

Answer:

Operation the correct answer for the given question.

Explanation:

An operation is a template that is used as a template parameter .An operation defined the services and behaviors of the class .The operation is directly invoked on instance .

Attribute define the property of an entity it is not defined the services and behaviors of the class. so this option is incorrect.

Class is the class of variable of method it is not defined the services and behaviors of the class  so this option is incorrect.

Object are the rub time entity .object are used access the property of a class it is not defined the services and behaviors of the class  so this option is incorrect.

Abstract class is the class which have not full implementation of all the method .it is not defined the services and behaviors of the class  so this option is incorrect.

So the correct answer is operation.

What is the tool that is used to automatically search New information on the internet and organize if for future searches?

Answers

the answer would be a "web crawler"

(Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 654 public static int reverse(int number) // Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

Answers

Answer:

import java.util.Scanner;

public class PalindromeInteger {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user's inputs

 Scanner input = new Scanner(System.in);

 // Create a prompt to display the aim of the program.

 System.out.println("Program to check whether or not a number is a palindrome");

 // Prompt the user to enter an integer number.

 System.out.println("Please enter an integer : ");

 // Receive user's input and store in an int variable, number.

 int number = input.nextInt();

 // Then, call the isPalindrome() method to check if or not the

 // number is a  palindrome integer.

 // Display the necessary output.

 if (isPalindrome(number)) {

  System.out.println(number + " is a palindrome integer");

 }

 else {

  System.out.println(number + " is a not a palindrome integer");

 }

}

// Method to return the reversal of an integer.

// It receives the integer as a parameter.

public static int reverse(int num) {

 // First convert the number into a string as follows:

 // Concatenate it with an empty quote.

 // Store the result in a String variable, str.

 String str = "" + num;

 // Create and initialize a String variable to hold the reversal of the  

 // string str. i.e rev_str

 String rev_str = "";

 // Create a loop to cycle through each character in the string str,

 // beginning at  the last character down to the first character.

 // At every cycle, append the character to the rev_str variable.

 // At the end of the loop, rev_str will contain the reversed of str

 for (int i = str.length() - 1; i >= 0; i--) {

  rev_str += str.charAt(i);

 }

 // Convert the rev_str to an integer using the Integer.parseInt()

 // method.  Store the result in an integer variable reversed_num.

 int reversed_num = Integer.parseInt(rev_str);

 // Return the reversed_num

 return reversed_num;

}

// Method to check whether or not a number is a palindrome integer.

// It takes in the number as parameter and returns a true or false.

// A number is a palindrome integer if reversing the number does not

//  change the  number itself.

public static boolean isPalindrome(int number) {

 // check if the number is the same as its reversal by calling the

 //reverse()  method declared earlier. Return true if yes, otherwise,

               // return false.

 if (number == reverse(number)) {

  return true;

 }

 return false;

}

}

Explanation:

The source code file for the program has also been attached to this response for readability. Please download the file and go through the comments in the code carefully as it explains every segment of the code.

Hope this helps!

Which of the following sorting algorithms is described by this text? "Take the item at index 1 and see if it is in order compared to the item at index 0. If it is not, then swap the two items. Next take the item at index 2 and compare it to the items at the lower indexes. Move items in the lower indexes to a higher one until you find the proper location to place the value so that it is in the correct order. Continue this process with all remaining indexes."a. Insertion sort
b. Heap sort
c. Merge sort
d. Quick sort
e. Selection sort

Answers

Answer:

a. Insertion sort

Explanation:

Insertion Sort is a sorting algorithm that places the input element at its suitable place in each pass.

Insertion sort is based on the idea that one element from the input elements is consumed in each iteration to find its correct position.

Other Questions