Ad Code

Responsive Advertisement

Printing the pattern using C program

 

Printing the pattern Using C program

pattern program


C Program:

Output:

pattern program

From the above program,

ü Let num=3.

i

i<=num

j

j<=i

Print sum

Sum=sum+1

j++

Print new line

i++

1

1<=3

1

1<=1

1

Sum=1+1=2

2

Doesn’t execute

2

2<=1

false

Doesn’t execute

Print new line

2

2

2<=3

1

1<=2

1

2

Sum=2+1=3

2

Doesn’t execute

2

2<=2

1

2 3

Sum=3+1=4

3

3

3<=2

false

Doesn’t execute

Print new line

3

3

3<=3

1

1<=3

1

2 3

4

Sum=4+1=5

2

Doesn’t execute

2

2<=3

1

2 3

4 5

Sum=5+1=6

3

3

3<=3

1

2 3

4 5 6

Sum=6+1=7

4

4

4<=3

false

Doesn’t execute

Print new line

4

4

4<=3

false

Doesn’t execute

 

ü  i is the outer loop and j is the inner loop.

ü whenever j loop starts it's value will be assigned to 1.

ü j loop continues till the condition j<=i fails then only it moves to the outer loop i.

ü when j loop fails, new line will be printed then it moves to i loop.

ü when condition i<=num fails in i loop then the execution stops.

Note: If you are using mobile then view in desktop site to get the better view of the table.

Post a Comment

0 Comments

Close Menu