Q:

Program to print the following pattern

belongs to collection: Pattern Programs

0

Algorithm

  1. Start
  2. Let i be an integer number.
  3. Let j be an integer number.
  4. Repeat step 5 to 8 until all value parsed.
  5. Set i = 0 and check i<10;
  6. Set j = 0 and check j <= 10;
  7. Check conditions if(i==0 or i==10 or j==0 or j==10)
  8. If true print ?1? else print space.
  9. End

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

JAVA

import 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();   
    }  
        }}  

 

Python

def 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# program

using 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 program

    for ($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>";   
}  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to print the following pattern... >>
<< Program to print the following pattern...