Star Patterns in C/C++
Star Patterns in C/C+
In this Blog you will Learn how to print the Star Pattern in C/C++, These are the Most common star pattern usually practiced to enhance your Logical Thinking & Problem solving skills. In this blog almost all basic star pattern are given in C.
1. Regtangular
// Regtangle pattern using c programming
#include<stdio.h>
int main(){
int m,n;
printf("Enter Number of Rows & Columns\n");
scanf("%d %d",&m ,&n);
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
printf("*\t");
}
printf("\n");
}
return 0;
}
2. Right Half Pyramid
//Triagle pattern program
#include<stdio.h>
int main(){
int m;
printf("Enter Number of Rows & Columns\n");
scanf("%d",&m);
for(int i=1;i<=m;i++){
for(int j=1;j<=i;j++){
printf("*\t");
}printf("\n");
}
return 0;
}
3. Left Half Pyramid
#include<stdio.h>
int main(){
int m;
printf("Enter Number of Rows & Columns\n");
scanf("%d",&m);
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(j<=m-i){
printf(" \t");
}else{
printf("*\t");
}
}
printf("\n");
}
return 0;
}
4. Inverted Right Half Pyramid
#include<stdio.h>
int main(){
int m;
printf("Enter Number of Rows & Columns\n");
scanf("%d",&m);
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(j<m-i){
printf("*\t");
}else{
printf(" \t");
}
}
printf("\n");
}
return 0;
}
5. Inverted Left Half Pyramid
#include<stdio.h>
int main(){
int m;
printf("Enter Number of Rows & Columns\n");
scanf("%d",&m);
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(j>=i){
printf("*\t");
}else{
printf(" \t");
}
}
printf("\n");
}
return 0;
}
6. Full Pyramid
#include<stdio.h>
int main(){
int m,n;
printf("Enter a odd number of rows:");
scanf("%d",&m);
n=(2*m)-1;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(j<=m-i){
printf(" \t");
}
else if(j>=m+i){
printf(" \t");
}
else{
printf("*\t");
}
}
printf("\n");
}
return 0;
}
7. Inverted Full Pyramid
#include<stdio.h>
int main(){
int m,n;
printf("Enter a odd number of rows:");
scanf("%d",&m);
n=(2*m)-1;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(j<=i || j>=(m)+(m-i)){
printf(" \t");
}else{
printf("*\t");
}
}
printf("\n");
}
return 0;
}
8. Rhombus
#include<stdio.h>
int main(){
int m;
printf("Enter Number of rows:");
scanf("%d",&m);
for(int i=0;i<m;i++){
for(int a=0;a<=i;a++){
printf(" \t");
}
for(int j=0;j<m;j++){
printf("*\t");
}printf("\n");
}
return 0;
}
9. Diamond
#include<stdio.h>
int main(){
int m,n,mid;
printf("Enter a Even Number:");
scanf("%d" ,&m);
n=(m-1);
mid=m/2;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(i<=mid){
if(j<=mid-i || j>=mid+i){
printf(" ");
}else{
printf("*");
}
}
else if(i>mid){
if(j<(i-mid) || j>(mid)+mid-(i-mid)){
printf(" ");
}else{
printf("*");
}
}
}printf("\n");
}
return 0;
}
10. Hollow Square
#include<stdio.h>
int main(){
int m,n;
printf("Enter m & n:");
scanf("%d %d" ,&m ,&n);
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(i==1 || i==n){
printf("*");
}else if(j==1|| j==n){
printf("*");
}else{
printf(" ");
}
}printf("\n");
}
return 0;
}
11. Floyd's Triangle
#include<stdio.h>
int main(){
int m;
printf("Enter a number of rows:");
scanf("%d",&m);
int a=1;
for(int i=0;i<m;i++){
for(int j=0;j<=i;j++){
printf("%d\t",a);
a+=1;
}printf("\n");
}
return 0;
}
#include<stdio.h>
int main(){
int m;
printf("Enter a number of rows:");
scanf("%d",&m);
int a=1;
for(int i=0;i<m;i++){
for(int j=0;j<=i;j++){
printf("%d\t",a);
a+=1;
}printf("\n");
}
return 0;
}
Blog By: Jyotiba Maragannache
Comments
Post a Comment