C language programs for the following pattern
Pattern1:
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
Program:
#include<stdio.h>
#include<conio.h>
void pattern(int);
void main()
{
int n;
clrscr(); //clear the screen contents
printf("\nEnter N value: ");
scanf("%d",&n);
pattern(n);
getch();
}
void pattern(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("\n");
for(j=1;j<=n;j++)
{
printf("%d ",i);
}
}
}
Pattern2:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Program:
#include<stdio.h>
#include<conio.h>
void pattern(int);
void main()
{
int n;
clrscr(); //clear the screen contents
printf("\nEnter N value: ");
scanf("%d",&n);
pattern(n);
getch();
}
void pattern(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("\n");
for(j=1;j<=n;j++)
{
printf("%d ",j);
}
}
}
Pattern3:
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Program:
#include<stdio.h>
#include<conio.h>
void pattern(int);
void main()
{
int n;
clrscr(); //clear the screen contents
printf("\nEnter N value: ");
scanf("%d",&n);
pattern(n);
getch();
}
void pattern(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("\n");
for(j=1;j<=n;j++)
{
if(i==j)
{
printf("1 ");
}
else
{
printf("0 ");
}
}
}
}
Pattern4:
1
0 1
0 0 1
0 0 0 1
0 0 0 0 1
Program:
#include<stdio.h>
#include<conio.h>
void pattern(int);
void main()
{
int n;
clrscr(); //clear the screen contents
printf("\nEnter N value: ");
scanf("%d",&n);
pattern(n);
getch();
}
void pattern(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("\n");
for(j=1;j<=n;j++)
{
if(i==j)
{
printf("1 ");
}
else if(i>j)
{
printf("0 ");
}
else
{
printf(" ");
}
}
}
}
Pattern5:
1 0 0 0 0
1 0 0 0
1 0 0
1 0
1
Program:
#include<stdio.h>
#include<conio.h>
void pattern(int);
void main()
{
int n;
clrscr(); //clear the screen contents
printf("\nEnter N value: ");
scanf("%d",&n);
pattern(n);
getch();
}
void pattern(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("\n");
for(j=1;j<=n;j++)
{
if(i==j)
{
printf("1 ");
}
else if(i<j)
{
printf("0 ");
}
else
{
printf(" ");
}
}
}
}
Thanks for visiting............
0 comments:
Post a Comment