← Playground

Create BD_Citire_Diagonala

547332c6d63c8564a16be078cca976ced1df5cd5 · darakna · Jan 17, 2016 00:20

+57 · 1 file changed

  • BD_Citire_Diagonala +57 −0
diff --git a/BD_Citire_Diagonala b/BD_Citire_Diagonala
new file mode 100644
index 0000000..85ba272
--- /dev/null
+++ b/BD_Citire_Diagonala
@@ -0,0 +1,57 @@
+#include<iostream>
+#include<fstream>
+using namespace std;
+
+
+void selectedRead(int linii, int coloane, const int **p) {
+	for (int c = 0, l = 0; c + l <= linii + coloane - 2; c<coloane - 1 ? c++ : l++) {
+		int copyC = c;
+		int copyL = l;
+		while (copyC >= 0 && copyL <= linii - 1) {
+			cout << p[copyL][copyC] << ' ';
+			copyC--;
+			copyL++;
+		}
+	}
+}
+
+void main()
+{
+	int m,n,mat[20][20];
+	ifstream myReadFile;
+ myReadFile.open("in.txt");
+ myReadFile>>m>>n;
+ for(int i=0;i<m;i++)
+ {
+	 for(int j=0;j<n;j++)
+	 {
+		 myReadFile>>mat[i][j];
+	 }
+ }
+ for(int i=0;i<m;i++)
+ {
+	 for(int j=0;j<n;j++)
+	 {
+		 cout<<mat[i][j]<<" ";
+	 }
+	 cout<<endl; 
+ }
+ int sign=0;
+ cout << endl << endl;
+ //selectedRead( m, n,*mat);
+
+ for (int c = 0, l = 0; c + l <= m + n - 2; c<m - 1 ? c++ : l++) {
+	 int copyC = c;
+	 int copyL = l;
+	 while (copyC >= 0 && copyL <= n - 1) {
+		 cout << mat[copyL][copyC] << ' ';
+		 copyC--;
+		 copyL++;
+	 }
+	 cout << endl;
+ }
+
+ myReadFile.close();
+
+
+}