Last active
November 28, 2019 17:21
-
-
Save gryphon2411/7f393ba500c387d35856d63bc9e97197 to your computer and use it in GitHub Desktop.
אתחול מטריצה, קליטת ערכים לתוכה, ופליטת הערכים שנקלטו לתוכה
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
// מטריצה היא מערך רגיל, שכל תא בו הוא מערך בפני עצמו | |
// המשתנה בשם "מטריקס" הוא מערך שכל תא בו הוא מערך בפני עצמו ("אינט" עם כוכבית) - מה שהופך אותו למטריצה | |
// מאחורי הקלעים - מטריקס הוא מערך רגיל | |
// אתחול המטריצה | |
int **matrix, rows, columns, row, column; | |
cout << "Please enter number of rows:" << endl; | |
cin >> rows; | |
cout << "Please enter number of columns:" << endl; | |
cin >> columns; | |
// במערך "מטריקס" כל תא בו הוא מערך בפני עצמו, לכן משתמשים ב-("אינט" עם *) ולא רק ב-"אינט" לבד | |
matrix = new int*[rows]; | |
for (row = 0; row < rows; row++) { | |
// רצים על כל השורות, | |
// ומאתחלים כל שורה להיות מערך באורך של מספר העמודות | |
// בשלב זה רק מאתחלים את המטריצה - לא קולטים לתוכה ערכים | |
matrix[row] = new int[columns]; | |
} | |
// בשלב זה קולטים ערכים לתוך המטריצה שאתחלנו למעלה | |
for (row = 0; row < rows; row++) { | |
for (column = 0; column < columns; column++) { | |
cout << "Please enter a number in cell (" << row << ", " << column << "):" << endl; | |
cin >> matrix[row][column]; | |
} | |
} | |
// בשלב זה פולטים את כל הערכים שנקלטו במבנה של המטריצה | |
for (row = 0; row < rows; row++) { | |
for (column = 0; column < columns; column++) { | |
cout << matrix[row][column] << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment