pp10 Dsa The State Of Wakanda - 2 - Hindi Facts

Latest

Hindi Facts is information about current events. This may be provided through many different media: word of mouth, printing, postal systems, broadcasting, electronic communication, or through the testimony of observers and witnesses to events.

Subscribe Us

BANNER 728X90

गुरुवार, 29 अप्रैल 2021

pp10 Dsa The State Of Wakanda - 2

 import java.io.*;

import java.util.*;


public class Main {


    public static void main(String[] args) throws Exception {

        // write your code here

        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt ();

        

        int[][]mat = new int[n][n];

        

        for(int i = 0;i<n;i++){

            for(int j = 0;j<n;j++){

                mat[i][j] = scn.nextInt();

            }

        }

        

        printDiagonal(mat);

    }

    

    public static void printDiagonal(int[][]mat){

        int n = mat.length;

        

        //to select diagonal

        for(int d = 0;d<n;d++){

            //print dth diagonal

            for(int r = 0,c = d;c<n;r++,c++){

                System.out.println(mat[r][c]);

            }

        }

    }


}






कोई टिप्पणी नहीं:

एक टिप्पणी भेजें

if you have any douts please let me know