109.3.. Učitati dvodimenzionalni niz - matricu nxm. Izračunati i ispisati sumu elemenata pete kolone niza X[n,m]
Opis programa:
Tekstualni algoritam:
Listing programa:
package prvipaket;
import java.util.Scanner;
public class p10913005 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("unesi broj redova i kolona ");
int r = input.nextInt();
int k = input.nextInt();
int niz[][] = new int[r][k];
System.out.print("unesi clanove ");
for (int i = 0; i < niz.length; i++) {
for (int j = 0; j < niz[i].length; j++) {
System.out.print("X[" +i+ "," +j +"]"+ "-->");
niz[i][j] = input.nextInt();
}
}
for (int i = 0; i < niz.length; i++) {
System.out.println();
for (int j = 0; j < niz[i].length; j++) {
System.out.print(niz[i][j] + " ");
}
}
System.out.println();
int s = 0;
int j = 5; // 5. kolona
for (int i = 0; i < niz.length; i++)
s = s + niz[i][j];
System.out.print("Suma 5. kolone: " + s);
}
}
Ispis na ekranu:
Index
|