C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to print the following patternAlgorithm
JAVAimport java.util.Scanner; public class PatternBox { public static void main(String[] args) { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { if (i==1 || i==10 || j==1 || j==10 ) System.out.print(" 1"); else System.out.print(" "); } System.out.println(); } }} Pythondef box(r, c) : for i in range(1, r+1) : for j in range(1, c+1) : if (i == 1 or i == r or j == 1 or j == c) : print("1"), else : print(" "), print(" ") rows = 6 columns = 10 box(rows, columns) C program#include <stdio.h> int main() { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { if (i==1 || i==10 || j==1 || j==10 ) printf(" 1"); else printf(" "); } printf("\n"); } } C# programusing System; public class Program { public static void Main() { int row, i, j; row = 5; for (i = 0; i <= 10; i++) { for (j = 0; j <= 10 ; j++) { if (i == 0 || i == 10 || j == 0 || j== 10) Console.Write("1"); else Console.Write(" "); } Console.WriteLine(); } } } PHP programfor ($i = 1; $i <= 10; $i++) { for ($j = 1; $j <= 10; $j++) { if ($i==1 || $i==10 || $j==1 || $j==10 ) { echo "1"; } else { echo " "; } } echo "<br>"; }
Next TopicProgram to Print pattern 13
|