78
Write a program to print the following pattern.
*000*000*
0*00*00*0
00*0*0*00
000***000
Algorithm
- STEP 1: START
- STEP 2: SET lines=4
- STEP 3: Initialize i and j
- STEP 4: SET i =1
- STEP 5: REPEAT STEP 6 to 15 UNTIL i less than or equals to line
- STEP 6: SET j=1
- STEP 7: REPET STEP 8 and 9 UNTIL j is less than or equals to lines
- STEP 8: IF i is equal to j PRINT * ELSE PRINT 0
- STEP 9: SET j = j + 1
- STEP 10: DECREMENT j by 1 and PRINT *
- STEP 11: REPEAT STEP 12 and 13 UNTIL j is greater than 0
- STEP 12: IF i is equals to j PRINT * ELSE PRINT 0
- STEP 13: SET j = j – 1
- STEP 14: PRINT a new line
- STEP 15: SET i = i + 1
- STEP 16: EXIT
Solution:
C Program:
Output:
*000*000* 0*00*00*0 00*0*0*00 000***000
Java Program:
Output:
*000*000* 0*00*00*0 00*0*0*00 000***000
C# Program:
Output:
*000*000* 0*00*00*0 00*0*0*00 000***000
PHP Program:
Output:
*000*000* 0*00*00*0 00*0*0*00 000***000
Python Program:
Output:
*000*000* 0*00*00*0 00*0*0*00 000***000
Next TopicProgram to Print the Pattern 4