Pattern Program in C Programming Language (post - 1)
In this blog you will get * Pattern Programs. For chapterwise program list click here
This blog is our first blog for Pattern Programs. If you want to know more about * Pattern Programs also read from below link.
Read out second post about parttern programmingProgram1:
#include void main() { int i, j ; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=5 ; j++) { printf("* "); } printf("\n"); } }
Output:
* * * * * * * * * * * * * * * * * * * * * * * * *
Program2:
/** * C program to print square star pattern */ #include int main() { int i, j, N; // Input number of rows from user printf("Enter number of rows: "); scanf("%d", &N); // Iterate over rows for(i=1; i<=N; i++) { // Iterate over columns for(j=1; j<=N; j++) { // Print star for each column printf("*"); } // Move to the next line/row printf("\n"); } return 0; }
Output:
Enter number of rows: 6 ****** ****** ****** ****** ****** ******
Program3:
#include void main() { int i, j ; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=5 ; j++) { printf("%d ", i); } printf("\n"); } }
Output:
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
Program4:
#include void main() { int i, j ; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=5 ; j++) { printf("%d ",j); } printf("\n"); } }
Output:
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Program5:
#include void main() { int i; for(i=1 ; i<=25 ; i++) { printf("* "); if(i%5==0) printf("\n"); } }
Output:
* * * * * * * * * * * * * * * * * * * * * * * * *
Program6:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=i ; j++) { printf("* "); } printf("\n"); } }
Output:
* * * * * * * * * * * * * * *
Program7:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=i ; j++) { printf("%d ", i); } printf("\n"); } }
Output:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Program8:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=1 ; j<=i ; j++) { printf("%d ", j); } printf("\n"); } }
Output:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Program9:
#include void main() { int i, j; for(i=5 ; i>=1 ; i--) { for(j=5 ; j>=i ; j--) { printf("%d ", j); } printf("\n"); } }
Output:
5 5 4 5 4 3 5 4 3 2 5 4 3 2 1
Program10:
#include void main() { int i, j; for(i=5 ; i>=1 ; i--) { for(j=i ; j<=5 ; j++) { printf("%d ", j); } printf("\n"); } }
Output:
5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
Program11:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=i ; j>=1 ; j--) { printf("%d ", j); } printf("\n"); } }
Output:
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
Program12:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=i ; j<=5 ; j++) { printf("%d ", j); } printf("\n"); } }
Output:
1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
Program13:
#include void main() { int i, j; for(i=1 ; i<=5 ; i++) { for(j=5 ; j>=i ; j--) { printf("%d ", j); } printf("\n"); } }
Output:
5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
Program14:
#include void main() { int i, j; for(i=5 ; i>=1 ; i--) { for(j=i ; j>=1 ; j--) { printf("%d ", j); } printf("\n"); } }
Output:
5 4 3 2 1 4 3 2 1 3 2 1 2 1 1Read out second post about parttern programming