In this tutorial, we will discuss a concept of C program to Integrated triangle patterns using for loop
In C language, we can use for loop ,while loop and do-while loop to display different number (binary, decimal), alphabets or star pattern programs.
In this article, we are going to learn how to Display Integrated triangle patterns using for loop in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows: "); scanf("%d",&rows); //get input from user for rows for(i=1; i<=rows; i++){ //parent for loop for(j=1; j<=i; j++){ printf("*"); } for(j=i*2; j<rows*2; j++){ printf(" "); } for(k=i; k>=1; k--){ printf("*"); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows: "); scanf("%d",&rows); //get input from user for rows for(i=rows; i>=1; i--){ //parent for loop for(j=rows; j>=1+rows-i; j--){ printf("*"); } for(j=i*2; j<rows*2-1; j++){ printf(" "); } for(k=1+rows-i; k<=rows; k++){ if(k!=1) printf("*"); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows: "); scanf("%d",&rows); //get input from user for rows for(i=1; i<=rows; i++){ //parent for loop for(j=1; j<=i; j++){ printf("%d",j); } for(j=i*2; j<rows*2; j++){ printf(" "); } for(k=i; k>=1; k--){ printf("%d",k); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows: "); scanf("%d",&rows); //get input from user for rows for(i=rows; i>=1; i--){ //parent for loop for(j=rows; j>=1+rows-i; j--){ printf("%d",j); } for(j=i*2; j<rows*2-1; j++){ printf(" "); } for(k=1+rows-i; k<=rows; k++){ if(k!=1) printf("%d",k); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows: "); scanf("%d",&rows); //get input from user for rows for(i=rows; i>=1; i--){ for(j=1; j<=i; j++){ printf("%d",j); } for(j=i*2; j<rows*2-1; j++){ printf(" "); } for(k=i; k>=1; k--){ if(k!=rows) printf("%d",k); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
Similar post
C++ code to Integrated triangle patterns using for loop
Java code to Integrated triangle patterns using for loop
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…