xxxxxxxxxx
INPUT : 5
OUTPUT :
*
* *
* * *
* * * *
* * * * *
#include <stdio.h>
void main(){
int i, j, n;
printf("Enter value of n: ");
scanf("%d", &n);
for(i=1; i<=n; i++){
for(j=1; j<=i; j++){
printf("*");
}
printf("\n");
}
}
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h> INPUT : 5
OUTPUT :
int main(void) *
{ * *
int n,k,i,j; * * *
setbuf(stdout,NULL); * * * *
printf("Enter the limit of the number = "); * * * * *
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
printf("* ");
}
return EXIT_SUCCESS;
}
xxxxxxxxxx
INPUT : 3
OUTPUT : * *
*
*
*
* * * *
*
*
*
*
*
*
* * * * * *
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n,i,j,k;
setbuf(stdout,NULL);
printf("Enter the number of patterns to be printed = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=(2*i);j++)
{
printf("* ");
}
printf("\n");
if(i==n)
{
break;
}
for(k=1;k<=(3*i);k++)
{
printf("* \n");
}
}
return EXIT_SUCCESS;
}
xxxxxxxxxx
INPUT : 3
OUTPUT : * *
*
*
*
* * * *
* * * *
*
*
*
* * * * * *
* * * * * *
* * * * * *
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n,i,j;
setbuf(stdout,NULL);
printf("Enter the number of patterns to be printed = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=(2*i*i);j++)
{
printf("* ");
if(j%(2*i)==0)
{
printf("\n");
}
}
if(i==n)
{
break;
}
for(j=1;j<=3;j++)
{
printf("* \n");
}
}
return EXIT_SUCCESS;
}
xxxxxxxxxx
INOUT : 8
OUTPUT : * *
*** ***
***** *****
******* *******
********* *********
*********** ***********
***********************
***********************
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n,i,j;
setbuf(stdout,NULL);
printf("Enter the number = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n*3-1;j++)
{
if((j<2*i)||(j>n*3-2*i))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return EXIT_SUCCESS;
}
xxxxxxxxxx
INPUT : 5
OUTPUT :
1
1 0
1 0 0
1 0 0 0
1 0 0 0 0
1 0 0 0
1 0 0
1 0
1
#include <stdio.h>
int main(void) {
int i,j,n;
printf("Enter the number = ");
scanf("%d",&n);
for (i=1; i<=n; i++) {
for (j=1; j<=i; j++) {
if (j==1){
printf(" 1");
}
else{
printf(" 0");
}
}
printf("\n");
}
for (i=n-1; i>=1; i--) {
for (j=1; j<=i; j++) {
if (j==1) {
printf(" 1");
}
else {
printf(" 0");
}
}
printf("\n");
}
return 0;
}
xxxxxxxxxx
INPUT : 6
OUTPUT :
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
#include <stdio.h>
void main() {
int i, j, rows;
printf("Enter number of rows : ");
scanf("%d", &rows);
for(i=1; i<=rows; i++){
for(j=i; j<rows; j++){
printf(" ");
}
for(j=1; j<=(2*i-1); j++){
printf("*");
}
printf("\n");
}
}
xxxxxxxxxx
INPUT : 7
OUTPUT :
* * * * * * *
* *
* *
* *
* *
* *
*
#include <stdio.h>
void main(){
int i, j, rows;
printf("Enter number of rows : ");
scanf("%d", &rows);
for(i=1; i<=rows; i++){
for(j=1; j<i; j++){
printf(" ");
}
for(j=i; j<=rows; j++){
if(j==i || j==rows || i==1){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");
}
}
xxxxxxxxxx
Input rows: 5
*
***
*****
*******
*********
/**
* C program to print equilateral triangle or pyramid star pattern
*/
#include <stdio.h>
int main()
{
int i, j, rows;
/* Input number of rows to print */
printf("Enter number of rows : ");
scanf("%d", &rows);
/* Iterate through rows */
for(i=1; i<=rows; i++)
{
/* Print leading spaces */
for(j=i; j<rows; j++)
{
printf(" ");
}
/* Print star */
for(j=1; j<=(2*i-1); j++)
{
printf("*");
}
/* Move to next line */
printf("\n");
}
return 0;
}