0% found this document useful (0 votes)
14 views2 pages

Additional Patterns

The document contains a series of C programming functions that generate various number and character patterns, including right-angled triangles, inverted triangles, binary triangles, and more. Each function is designed to print a specific pattern based on a defined size, with examples such as multiplication tables, rhombuses, and diamonds. The code showcases different looping techniques and formatting for outputting the patterns.

Uploaded by

Bibin K Bino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Additional Patterns

The document contains a series of C programming functions that generate various number and character patterns, including right-angled triangles, inverted triangles, binary triangles, and more. Each function is designed to print a specific pattern based on a defined size, with examples such as multiplication tables, rhombuses, and diamonds. The code showcases different looping techniques and formatting for outputting the patterns.

Uploaded by

Bibin K Bino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// 1.

Right Angled Number Triangle void rightAngledNumberTriangle() { int


n = 5; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { printf(”%d ”,
j); } printf(”\n”); } }
// 2. Inverted Right Angled Number Triangle void invertedNumberTriangle() {
int n = 5; for(int i = n; i >= 1; i--) { for(int j = 1; j <= i; j++) { printf(”%d
”, j); } printf(”\n”); } }
// 3. Binary Number Triangle void binaryTriangle() { int n = 5; for(int i =
1; i <= n; i++) { for(int j = 1; j <= i; j++) { printf(”%d ”, (i+j+1) % 2); }
printf(”\n”); } }
// 4. Character Pattern Triangle void characterTriangle() { int n = 5; for(int i
= 1; i <= n; i++) { for(int j = 1; j <= i; j++) { printf(”%c ”, ’A’ + j - 1); }
printf(”\n”); } }
// 5. Spiral Number Pattern void spiralNumberPattern() { int n = 4; int ma-
trix[10][10] = {0}; int num = 1; int left = 0, right = n-1, top = 0, bottom =
n-1;
while(num <= n*n) { // Left to Right for(int i = left; i <= right; i++) ma-
trix[top][i] = num++; top++;
// Top to Bottom for(int i = top; i <= bottom; i++) matrix[i][right] = num++;
right--;
// Right to Left for(int i = right; i >= left; i--) matrix[bottom][i] = num++;
bottom--;
// Bottom to Top for(int i = bottom; i >= top; i--) matrix[i][left] = num++;
left++; }
// Print the pattern for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++)
printf(”%2d ”, matrix[i][j]); printf(”\n”); } }
// 6. Number Pattern with Spaces void numberSpacePattern() { int n = 5;
for(int i = 1; i <= n; i++) { // Print spaces for(int j = 1; j <= n-i; j++)
printf(” ”); // Print increasing numbers for(int j = 1; j <= i; j++) printf(”%d
”, j); // Print decreasing numbers for(int j = i-1; j >= 1; j--) printf(”%d ”, j);
printf(”\n”); } }
// 7. Square Number Pattern void squareNumberPattern() { int n = 4; for(int
i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(i == 1 || i == n || j ==
1 || j == n) printf(”%d ”, n); else printf(”%d ”, n-1); } printf(”\n”); } }
// 8. Multiplication Table Pattern void multiplicationPattern() { int n = 5;
for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { printf(”%3d ”, i*j);
} printf(”\n”); } }
// 9. Rhombus Pattern void rhombusPattern() { int n = 5; for(int i = 1; i <=
n; i++) { // Print spaces for(int j = 1; j <= n-i; j++) printf(” ”); // Print
numbers for(int j = 1; j <= n; j++) printf(”%d ”, i); printf(”\n”); } }

1
// 10. Alternating Number Pattern void alternatingNumberPattern() { int n =
5; int num = 1; for(int i = 1; i <= n; i++) { if(i % 2 == 1) { // Odd rows
for(int j = 1; j <= i; j++) printf(”%d ”, num++); } else { // Even rows num
= num + i - 1; for(int j = 1; j <= i; j++) printf(”%d ”, num--); num = num +
i + 1; } printf(”\n”); } }
// 11. Pyramid with Row Numbers void rowNumberPyramid() { int n = 5;
for(int i = 1; i <= n; i++) { // Print spaces for(int j = 1; j <= n-i; j++)
printf(” ”); // Print row number i times for(int j = 1; j <= i; j++) printf(”%d
”, i); printf(”\n”); } }
// 12. Continuous Number Pattern void continuousNumberPattern() { int n =
4; int num = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) {
printf(”%2d ”, num++); } printf(”\n”); } }
// 13. X Pattern void xPattern() { int n = 5; for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) { if(j == i || j == n-i+1) printf(”*”); else printf(”
”); } printf(”\n”); } }
// 14. Z Pattern void zPattern() { int n = 5; for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) { if(i == 1 || i == n || j == n-i+1) printf(”*”); else
printf(” ”); } printf(”\n”); } }
// 15. Number Diamond with Row Count void numberDiamondRowCount()
{ int n = 5; // Upper half for(int i = 1; i <= n; i++) { // Spaces for(int j
= 1; j <= n-i; j++) printf(” ”); // Numbers for(int j = 1; j <= 2*i-1; j++)
printf(”%d”, i); printf(”\n”); } // Lower half for(int i = n-1; i >= 1; i--) { //
Spaces for(int j = 1; j <= n-i; j++) printf(” ”); // Numbers for(int j = 1; j <=
2*i-1; j++) printf(”%d”, i); printf(”\n”); } }

You might also like