0% found this document useful (0 votes)
64 views

To Print Patterns 1.

The document contains code snippets for printing various patterns using for loops in C programming. The patterns include numbers, stars, and reversed numbers. Each code snippet includes header files, a main function with nested for loops to print the pattern rows, and gets user input for the number of rows.

Uploaded by

Sunita Sapkota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

To Print Patterns 1.

The document contains code snippets for printing various patterns using for loops in C programming. The patterns include numbers, stars, and reversed numbers. Each code snippet includes header files, a main function with nested for loops to print the pattern rows, and gets user input for the number of rows.

Uploaded by

Sunita Sapkota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

To print patterns

1. 1
2 3
4 5 6
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,r=1;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",r);
r++;
}
printf("\n");
}
getch();
}

2.

*
* *
* * *
* * * *

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
getch();
}

3.

1
2 2
3 3 3
4 4 4 4

#include<stdio.h>
#include<conio.h>
void main()
{

int n,i,j;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i);
}
printf("\n");
}
getch();
}

4.

1
1 2
1 2 3
1 2 3 4

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
getch();
}

5.

5
4
3
2
1

4 3 2 1
3 2 1
2 1
1

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d ",j);
}
printf("\n");

}
getch();
}

6.

5
4
3
2
1

5 5 5 5
4 4 4
3 3
2

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
clrscr();
printf("enter value of n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d ",i);
}
printf("\n");
}
getch();
}

7.

1
121
12321
1234321
123454321

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,e,k;
for(i=1;i<=5;i++)
{
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(e=i-1;e>=1;e--)
{
printf("%d",e);
}
printf("\n");
}
getch();
}

8.

1
121
12321
1234321
123454321

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,e,k;
for(i=1;i<=5;i++)
{
for(j=5-i;j>0;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%d",k);
}
for(e=i-1;e>=1;e--)
{
printf("%d",e);
}
printf("\n");
}
getch();
}

9.

*
***
*****
*******
*********

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k;
printf("enter the number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
printf(" ");
for(k=1;k<=2*i-1;k++)
printf("*");
printf("\n");
}
getch();
}

You might also like