Found 33676 Articles for Programming

Java program to print star Pascal\'s triangle

AmitDiwan
Updated on 09-Sep-2024 01:19:20

724 Views

In this article, we will understand how to print star Pascal’s triangle in Java. The Pascal’s triangle is formed by using multiple for-loops and print statements. All values outside the triangle are considered zero (0). The first row is 0 1 0 whereas only 1 acquire a space in Pascal’s triangle, 0s are invisible. The second row is acquired by adding (0+1) and (1+0). The output is sandwiched between two zeroes. The process continues till the required level is achieved. Problem Statement Write a program in Java to print star Pascal's triangle. Below is a demonstration of the same − ... Read More

C++ program to find out the number of coordinate pairs that can be made

Arnab Chakraborty
Updated on 25-Feb-2022 11:29:45

1K+ Views

Suppose, we are given 2n number of coordinates on a two-dimensional plane. The 2n coordinates are divided into two arrays coordA, and coordB. The coordinates are represented as integer pairs. Now we have to form coordinate pairs that will contain one point from coordA and one point from coordB. We can make pairs if and only if the x coordinate of the point from coordA is smaller than that of the point from coordB, and the y coordinate of the point from coordA is smaller than that of the point from coordB. We have to find out the number of ... Read More

Java program to print downward triangle star pattern

Manisha Chand
Updated on 22-Aug-2025 15:31:15

877 Views

In this article, we will understand how to print a downward triangle star pattern using Java. In this pattern, the face of the triangle will be in a downward direction, and the base will be in an upward direction. We will learn through two examples: one where the user inputs the number of rows, and another where the number of rows is predefined in the program. Problem Statement Write a Java program to print a downward triangle star pattern. Below is a demonstration of the same. Input: Enter the number of rows : 8 Output: The downward triangle star pattern ... Read More

C++ program to find out the maximum sum of a minimally connected graph

Arnab Chakraborty
Updated on 25-Feb-2022 11:18:57

252 Views

Suppose, we are given a minimally connected graph. That means removing any edge will make the graph disconnected. The graph has n vertices and the edges are given in an array 'edges'. There is also an array 'vertexValues' given to us that contain n integer values.Now, we do the following −We write a positive integer on each of the vertices and then try to calculate a score.There is an edge connecting two vertices, we put the smaller value of the two vertices on the edges.We calculate the score by adding all the edge values.We have to find the maximum value ... Read More

Java Program to Print Mirror Upper Star Triangle Pattern

AmitDiwan
Updated on 25-Feb-2022 11:10:15

493 Views

In this article, we will understand how to print mirror upper star triangle pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −The mirror upper star pattern : ******** ******* ****** ***** **** *** ** *AlgorithmStep 1 - START Step 2 - Declare four integer values namely i, ... Read More

Java Program to Print Upper Star Triangle Pattern

Alshifa Hasnain
Updated on 07-Jan-2025 18:56:02

997 Views

In this article, we will learn to print the upper star triangle pattern in Java. Printing patterns is a common exercise to strengthen the understanding of loops in programming. One of the most popular patterns is the Upper Star Triangle, which visually resembles an inverted right-angled triangle of stars aligned from the top. Below is a demonstration of the same − Input Enter the number of rows : 8 Output The upper star triangle star pattern : * ... Read More

C++ Program to find out the cost to travel all the given coordinates

Arnab Chakraborty
Updated on 25-Feb-2022 11:07:24

265 Views

Suppose, we are given n three-dimensional coordinates. The cost to travel from coordinate (a, b, c) to (x, y, z) is ∣ x − a∣ + ∣ y − b∣ + max(0, z − c). We start from the first coordinate, then visit all the coordinates at least once, and then return to the first coordinate. We have to find out the total cost of this whole trip. The coordinates are given to us in the array 'coords'.So, if the input is like n = 3, coords = {{1, 1, 0}, {1, 3, 4}, {3, 2, 2}}, then the output ... Read More

C++ Program to find out the number of jumps needed for a robot to reach a particular cell in a grid

Arnab Chakraborty
Updated on 25-Feb-2022 10:46:30

256 Views

Suppose, we have a grid of dimensions h x w. The grid is represented in a 2D array called ‘initGrid’, where each cell in the grid is either represented by a '#' or a '.'. '#' means that the grid contains an obstacle and '.' means that there is a path through that cell. Now, a robot is placed on a cell 'c' on the grid having row number x and column number y. The robot has to travel to another cell 'd' having row number p and column number q. Both the cell coordinates c and d are presented ... Read More

C++ Program to find out the number of unique matrices that can be generated by swapping rows and columns

Arnab Chakraborty
Updated on 25-Feb-2022 10:31:41

193 Views

Suppose, we have a n x n matrix. Each element in the matrix is unique and is an integer number between 1 and n2. Now we can perform the operations below in any amount and any order.We pick any two integers x and y that are in the matrix, where (1 ≤ x < y ≤ n) and swap the columns containing x and y.We pick any two integers x and y that are in the matrix, where (1 ≤ x < y ≤ n) and swap the rows containing x and y.We have to note that x + y ... Read More

C++ Program to find out the total cost required for a robot to make a trip in a grid

Arnab Chakraborty
Updated on 25-Feb-2022 10:05:21

197 Views

Suppose, we are given a grid of dimensions h x w. Each cell in the grid contains some positive integer number. Now there is a path-finding robot placed on a particular cell (p, q) (where p is the row number and q is the column number of a cell) and it can be moved to cell (i, j). A move operation has a particular cost, which is equal to |p - i| + |q - j|. Now there are q number of trips, which has the following properties.Each trip has two values (x, y) and there is a common value ... Read More

Advertisements