we can also get the same value by storing the value and multiplying the value by 11; val=1; val=val*11; in the loop till nth row,] but the drawback of this logic is that we wont be able to print the space between the digits. we can do that but the size of the code will be larger and not optimized :(
i found out a logic which is that the current element is sum eleemnt at position arr[i-1][j-1]+arr[i-1[j] which is true for all element but still my code is not getting accepted even after my output are correct for each input
import java.util.Scanner; public class PascalsTriangle { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of rows for Pascal's Triangle: "); int rows = scanner.nextInt();
// Generate Pascal's Triangle int[][] triangle = new int[rows][]; for (int i = 0; i < rows; i++) { // Initialize the current row triangle[i] = new int[i + 1]; triangle[i][0] = 1; // First element is always 1 triangle[i][i] = 1; // Last element is always 1
// Fill in the values in between for (int j = 1; j < i; j++) { triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j]; } } // Print Pascal's Triangle for (int i = 0; i < rows; i++) { for (int j = 0; j < triangle[i].length; j++) { System.out.print(triangle[i][j] + " "); } System.out.println(); } scanner.close(); } }
Beta, jo bhi kuch hu aap sab k pyaar ki vja se he hu. The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos. So, keep motivating, keep learning and keep loving Pepcoding😊
Hello Sir . I had a question . I am in 3rd yr .I have a basic understanding of all DS and Algos but still whenever I try to solve a problem , I am unable to do so . Mai ques ko sahi se approach hi nhi kr pata aur agr approach pta chal jaye to use code m nhi convert kr pata . Mughe har ques m same problem hoti h :( I am thinking of joining a batch at PEPCODING . Which one of your batches will be best for me ? I want to join a batch in which main focus will be on solving problems only that too relevant to interview ??
The pattern you've provided is known as Pascal's Triangle. Each number in the triangle is the sum of the two numbers directly above it.
Worth it!!
we can also get the same value by storing the value and multiplying the value by 11;
val=1;
val=val*11;
in the loop till nth row,]
but the drawback of this logic is that we wont be able to print the space between the digits.
we can do that but the size of the code will be larger and not optimized :(
how can you print 10 with this logic even if space was not the issue?
i found out a logic which is that the current element is sum eleemnt at position arr[i-1][j-1]+arr[i-1[j] which is true for all element but still my code is not getting accepted even after my output are correct for each input
Thanks for Explaining sir!!
We always appreciate sincerity. Keep learning beta
the whole playlist are hidden gem...
60th vedio
29/08/2024
import java.util.Scanner;
public class PascalsTriangle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of rows for Pascal's Triangle: ");
int rows = scanner.nextInt();
// Generate Pascal's Triangle
int[][] triangle = new int[rows][];
for (int i = 0; i < rows; i++) {
// Initialize the current row
triangle[i] = new int[i + 1];
triangle[i][0] = 1; // First element is always 1
triangle[i][i] = 1; // Last element is always 1
// Fill in the values in between
for (int j = 1; j < i; j++) {
triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
}
}
// Print Pascal's Triangle
for (int i = 0; i < rows; i++) {
for (int j = 0; j < triangle[i].length; j++) {
System.out.print(triangle[i][j] + " ");
}
System.out.println();
}
scanner.close();
}
}
aap students ke liye Massiah se kam thodi na hain sir.
Beta, jo bhi kuch hu aap sab k pyaar ki vja se he hu. The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating, keep learning and keep loving Pepcoding😊
Sir please or videos daliye
Hello Sir . I had a question . I am in 3rd yr .I have a basic understanding of all DS and Algos but still whenever I try to solve a problem , I am unable to do so . Mai ques ko sahi se approach hi nhi kr pata aur agr approach pta chal jaye to use code m nhi convert kr pata . Mughe har ques m same problem hoti h :( I am thinking of joining a batch at PEPCODING . Which one of your batches will be best for me ? I want to join a batch in which main focus will be on solving problems only that too relevant to interview ??
Ap soln na dekho 2ghante tkaur code jo bhi kro khud se likho
bhai aab aap konsi company me lag gaye ho
please bata do motivate hone ke liye
hello naman tell me how to tackled this problem and now what are you doing .
Sumit sir 🤍