Set 2
Using Dart Programming Language create the following patterns
1.
void main() {
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
print("*");
}
print("");
}
}
Output
2.
void main() {
int n = 4; // Number of rows for the pattern
int currentNumber = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
// Print the current number and a space
print('$currentNumber ');
currentNumber++;
}
// Move to the next line after each row
print('');
Output
3.
void main() {
int n = 4; // Number of rows for the pattern
for (int i = 1; i <= n; i++) {
// Print spaces before the numbers
for (int j = 1; j <= n - i; j++) {
print(' '); // 4 spaces for each number
// Print increasing numbers
for (int j = 1; j <= i; j++) {
print('${j.toString().padLeft(4)}');
// Print decreasing numbers
for (int j = i - 1; j >= 1; j--) {
print('${j.toString().padLeft(4)}');
print(''); // Move to the next line
4.
void main() {
List<String> words = ["F", "L U", "T T E", "R &", "D A R T"];
for (int i = 0; i < words.length; i++) {
String word = words[i];
int spaces = (words.length - 1 - i) * 2;
for (int j = 0; j < spaces; j++) {
print(' '); // Print spaces
for (int j = 0; j < word.length; j++) {
if (word[j] != ' ') {
print(word[j]); // Print letters
} else {
print(' '); // Print extra spaces
}
}
print(''); // Move to the next line
Output
5.
void main() {
int numRows = 6; // Number of rows for Pascal's Triangle
for (int i = 0; i < numRows; i++) {
// Print spaces before each row
for (int j = 0; j < numRows - i; j++) {
print(' '); // Three spaces for each number
int number = 1; // The first number in each row is always 1
for (int j = 0; j <= i; j++) {
// Print the current number and spaces
print('${number.toString().padLeft(3)} ');
// Calculate the next number based on the previous number
number = number * (i - j) ~/ (j + 1);
print(''); // Move to the next line
Output
6.
void main() {
int numRows = 5; // Number of rows for the star pattern
// Print the top half of the star pattern
for (int i = 1; i <= numRows; i++) {
// Print spaces before stars
for (int j = 1; j <= numRows - i; j++) {
print(' '); // Three spaces for each star
// Print stars
for (int j = 1; j <= i * 2 - 1; j++) {
print(' * ');
}
print(''); // Move to the next line
// Print the bottom half of the star pattern
for (int i = numRows - 1; i >= 1; i--) {
// Print spaces before stars
for (int j = 1; j <= numRows - i; j++) {
print(' '); // Three spaces for each star
// Print stars
for (int j = 1; j <= i * 2 - 1; j++) {
print(' * ');
print(''); // Move to the next line
Output