Yudiz Solutions (patterns)
Yudiz Solutions (patterns)
---
5. **Floyd's Triangle**
```js
function floydTriangle(n) {
let num = 1;
for (let i = 1; i <= n; i++) {
let row = '';
for (let j = 1; j <= i; j++) {
row += num + ' ';
num++;
}
console.log(row);
}
}
floydTriangle(5);
```
---
### **Medium Pattern Programs:**
1. **Pyramid Pattern**
```js
function pyramid(n) {
for (let i = 1; i <= n; i++) {
let space = ' '.repeat(n - i);
let stars = '* '.repeat(i);
console.log(space + stars);
}
}
pyramid(5);
```
3. **Diamond Pattern**
```js
function diamond(n) {
for (let i = 1; i <= n; i++) {
let space = ' '.repeat(n - i);
let stars = '* '.repeat(i);
console.log(space + stars);
}
for (let i = n - 1; i >= 1; i--) {
let space = ' '.repeat(n - i);
let stars = '* '.repeat(i);
console.log(space + stars);
}
}
diamond(5);
```
5. **Pascal’s Triangle**
```js
function pascalTriangle(n) {
let arr = [];
for (let i = 0; i < n; i++) {
arr[i] = new Array(i + 1);
for (let j = 0; j <= i; j++) {
if (j === 0 || j === i) {
arr[i][j] = 1;
} else {
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
process.stdout.write(arr[i][j] + " ");
}
console.log();
}
}
pascalTriangle(5);
```
Output for `n=5`:
```
1
11
121
1331
14641
```
---
These programs cover both basic and medium-difficulty levels. You can further modify
them to experiment with different patterns. Let me know if you need more complex
patterns or further explanations!
Here are some pattern programs that combine **numbers** and **stars (`*`)**:
---
---
---
These programs showcase the combination of numbers and stars in various formats like
triangles, pyramids, and diamonds. Let me know if you need further variations or
explanations!