My Subject Blog

C Program for Pyramid and Pattern

/*
Pattern Programs:(WAP to print pattern like below)

*  
*  *  
*  *  *  
*  *  *  * 

*/

#include <stdio.h>

int main(void) {
int i,j,n;
printf("Enter How Many Rows You Want :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;

}

/*
Pattern Programs:(WAP to print pattern like below)


2 2 
3 3 3 
4 4 4 4

*/

#include <stdio.h>

int main(void) {
int i,j,n;
printf("Enter How Many Rows You Want :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",i+1);
}
printf("\n");
}
return 0;
}

/*

Pattern Programs:(WAP to print pattern like below)

1  
0 1  
1 0 1  
0 1 0 1

*/

#include <stdio.h>

int main(void) {
int i,j,n;
printf("Enter How Many Rows You Want :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",(i+j+1)%2);
}
printf("\n");
}
return 0;
}

/*
Pattern Programs:(WAP to print pattern like below)

4 3 2 1 
3 2 1 
2 1 
1

*/

#include <stdio.h>

int main(void) {
int i,j,n;
printf("Enter How Many Rows You Want :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
printf("%d ",n-i-j);
}
printf("\n");
}
return 0;

}

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

Followers