Pattern1 in C language

 Nested loop 

C programming language allows to use one loops inside another loop is know as nested loop 

Syntax:
for(init;condition;increment)
{
    for(init;condition;increment)
{
    statement(s);
}
statement(s);
}
p1-program to print following pattern
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
 program-
#include<stdio.h>
void main()
 {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
  printf("%d ",j);}

printf("\n");}
 }

P2-program to print following pattern
 1  1  1  1  1
 2  2  2  2  2
 3  3  3  3  3
 4  4  4  4  4
 5  5  5  5  5
program-
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for (j=1;j<=5;j++)
{
printf(" %d ",i);}
printf("\n");
}
}

P3-Program to print following pattern 
 * * * * *
 * * * * *
 * * * * *
 * * * * *
 * * * * *
 code-
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
printf(" *");
printf("\n");
}

P4-program to print following pattern
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
code-
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=65;j<=69;j++)
printf("%C ",j);
printf("\n");
}
}

P5-program to print following pattern
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1

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

P6-program to print following pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
code-
#include<Stdio.h>
void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("%d ",j);
printf("\n");
}
}




Comments

Popular posts from this blog

CYBER SECURITY & CRACKING PASSWORDS

"The Dark Side of Social Media: How It Fuels Digital Addiction and Impacts Mental Health"

Online Platforms to Learn Coding