Question: I'm trying to create a C program that prints a triangular pattern according to height by only using 1, 2 and 3 to generate the patterns:

```
Enter the height:
7
Pattern:
1
22
333
1111
22222
333333
1111111

```

I am only able to print the numbers but I do not know how to print only using 1, 2 and 3

This is my code so far:

```
printf("Enter the height: \n");
scanf("%d", &height);

if(height <0 || height > 10){
    printf("Please enter height within 1 to 10!");
}
else{
    printf("Pattern: \n");

    for(row=1; row<=height; row++){
        for(int col=1; col<=row; col++){
             printf("%d", row );
        }
        printf("\n");
    }
return 0;
}

```

The output:

```
Enter the height:
7
Pattern:
1
22
333
4444
55555
666666
7777777

```

Thank you

Answer: 
The change would be:

```
for(row=1; row<=height; row++){
    int num = row%3;
    if(num==0)
        num = 3;
    for(int col=1; col<=row; col++){
         printf("%d", num );
    }
    printf("\n");
}

```

Logic:  

1. Divide the value of `row` by 3 and get the remainder (i.e., perform `row % 3`).  

2. If the remainder is 0, it means that the row number is a multiple of 3. Therefore, print 3s.  

3. Otherwise, print the remainder.
use the mod operation % .. 
(number%4) is between 0 and 3 .. 
since you want it from 1 to 3 then take (number%3+1) ..

```
printf("Enter the height: \n");
scanf("%d", &height);

if(height <0 || height > 10){
   printf("Please enter height within 1 to 10!");
}
 else{
  printf("Pattern: \n");

  for(row=1; row<=height; row++){
      for(int col=1; col<=row; col++){
         printf("%d", (row%3)+1 );
    }
    printf("\n");
   }
 return 0;
}

```