Làm thế nào để bạn in một kim tự tháp rỗng đầy đủ trong python?
Ngày đăng:
07/01/2023
Trả lời:
0
Lượt xem:
151
Show
Các chương trình in đầy đủ mô hình kim tự tháp rỗng đã được cung cấp tại đây Nội dung trang1. Chương trình và đầu ra 1. 1. C 1. 2. C++ 1. 3. Java 1. 4. con trăn 1. 5. C# 1. Chương trình và đầu ra để in mẫu kim tự tháp đầy đủ1. 1. Chương trình C & đầu ra để in toàn bộ mô hình kim tự tháp rỗngC Mã đã được sao chép /****************************** alphabetacoder.com C program to print the full hollow pyramid pattern using * *******************************/ #include đầu ra Nhập số hàng. 6 * * * * * * * * * ************ 1. 2. Chương trình C++ và đầu ra để in toàn bộ mô hình kim tự tháp rỗngC++ Mã đã được sao chép /****************************** alphabetacoder.com C++ program to print the full hollow pyramid pattern using * *******************************/ #include đầu ra Nhập số hàng. 4 * * * * * ******* 1. 3. Chương trình Java và đầu ra để in toàn bộ mô hình kim tự tháp rỗngJava Mã đã được sao chép /****************************** alphabetacoder.com Java program to print the full hollow pyramid pattern using * *******************************/ import java.util.Scanner; class Main { public static void main(String[] args) { // declare instance of Scanner class Scanner sc = new Scanner(System.in); // declare variables int row, i, j; // take input System.out.print("Enter the number of rows: "); row = sc.nextInt(); // new line System.out.println(""); // display the pattern for (i = 1; i <= row; i++) { // print spaces before starting // position of each row for (j = 1; j <= row - i; j++) { System.out.print(" "); } // print * for (j = 1; j <= (2 * i - 1); j++) { // except for the last row if (i < row) { if (j == 1 || j == (2 * i - 1)) { System.out.print("*"); } else { System.out.print(" "); } } // for the last row else { System.out.print("*"); } } // new line System.out.println(""); } } } đầu ra Nhập số hàng. 5 * * * * * * * ********* 1. 4. Chương trình Python và đầu ra để in toàn bộ mô hình kim tự tháp rỗngcon trăn Mã đã được sao chép #******************************** # alphabetacoder.com #Python program to print the full #hollow pyramid pattern using * #********************************* # take input row = int(input("Enter the number of rows: ")) # new line print("") # display the pattern for i in range(1, row + 1): # print spaces before starting # position of each row for j in range(1, row - i + 1): print(" ", end = "") # print * for j in range(1, 2 * i): # except for the last row if i < row: if j == 1 or j == (2 * i - 1): print("*", end = "") else: print(" ", end = "") # for the last row else: print("*", end = "") # new line print("") đầu ra Nhập số hàng. số 8 * * * * * * * * * ** * * * *************** 1. 5. Chương trình C# và đầu ra để in toàn bộ mô hình kim tự tháp rỗngC# Mã đã được sao chép /****************************** alphabetacoder.com C# program to print the full hollow pyramid pattern using * *******************************/ using System; namespace HollowPyramid { class Program { static void Main(string[] args) { // declare variables int row, i, j; // take input Console.Write("Enter the number of rows: "); row = Convert.ToInt32(Console.ReadLine()); // new line Console.WriteLine(""); // display the pattern for (i = 1; i <= row; i++) { // print spaces before starting // position of each row for (j = 1; j <= row - i; j++) { Console.Write(" "); } // print * for (j = 1; j <= (2 * i - 1); j++) { // except for the last row if (i < row) { if (j == 1 || j == (2 * i - 1)) { Console.Write("*"); } else { Console.Write(" "); } } // for the last row else { Console.Write("*"); } } // new line Console.WriteLine(""); } // wait for user to press any key Console.ReadKey(); } } } đầu ra Nhập số hàng. 7 * * * * * * * * * ** * *************** Làm thế nào để in mô hình ngôi sao kim tự tháp ngược rỗng?Thuật toán. . Lấy Đầu vào của giá trị hàng cho Kim tự tháp ngược Chúng ta cần sử dụng ba vòng lặp, một là vòng lặp bên ngoài để thay đổi dòng và hai vòng lặp bên trong, một để in ngôi sao và vòng còn lại để in khoảng trắng Vòng lặp bên ngoài lặp lại hàng lần và in một dòng mới sau khi hoàn thành vòng lặp bên trong |