In "C" programming patterns are very important for understanding the concept of loops. Implementing loops any pattern can be produced. Here are some basic patterns in programming. I am using the Linux platform.
Pattern 1
Program
#include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { for(j=1; j<=i; j++) { if(j<=i) printf("*"); else printf(" "); } } }
The output for n=5 is
Pattern 2
Program
#include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { for(j=1; j<=n; j++) { if(j>=n+1-i) printf("*"); else printf(" "); } } }The output for n=5 is
Pattern 3
Program
#include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { for(j=1; j<=n; j++) { if(j<=n+1-i) printf("*"); else printf(" "); } } }
The output for n=5 is
Pattern 4
Program
#include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { for(j=1; j<=n; j++) { if(j>=i) printf("*"); else printf(" "); } } }
The output for n=5 is
Please don't forget to share and subscribe my blog.
No comments:
Post a Comment