עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

שאלה ב-C#

Featured Replies

פורסם

כתוב פעולה המקבלת מערך דו-מימדי ריבועי m של מספרים שלמים.

על הפעולה להעתיק למערך חד-מימדי a את המספרים שמופיעים במערך הדו מימדי פעם אחת בלבד ולהציגם כפלט.

זאת התוכנית שכתבתי

הרעיון היה לקחת תא ולבדוק את כל התאים הבאים אחריו ולספור אם זה מוצא תא אחד מהתאים שאחריו

ששווה לו ואם זה לא מוצא זה שם אותו במערך החד מימדי

וזה לא עבד...:

using System;
class Program
{
const int n = 3;
static void PrintArray (int[,] math)
{
int count=0,count2=0;
int[] arr = new int[n*n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{

for (int k = i+1; k < n; k++)
for (int z = j + 1; z < n; z++)
{
Console.WriteLine("i j: {0} k z: {1}", math[i, j],math[k,z]);
if (math[i, j] == math[k, z])
count++;
}
if (count == 0)
{
arr[count2] = math[i, j];
count2++;
}
count = 0;
}
}
for (int x = 0; x < count; x++)
Console.WriteLine("arr cell {0}: {1}", x, arr[x]);
}
static void Main(string[] args)
{
int[,] math ={ { -1, -1, -7 }, { -8, 0, 5 }, { 0, 6, 3 } };
PrintArray(math);
Console.Read();
}
}






פורסם

אני רואה בעיתיות בבדיקה:


for (int k = i+1; k < n; k++)
for (int z = j + 1; z < n; z++)
{
Console.WriteLine("i j: {0} k z: {1}", math[i, j],math[k,z]);
if (math[i, j] == math[k, z])
count++;
}

למה שלא תבדוק את המערך החדש ולא את המטריצה שיצרת?

פורסם

האם אתם מוגבלים באיך לממש את הפתרון ? אם אתם כבר לומדים את זה ב C#, אז למה לא להתפנק על האופציות השונות שהיא נותנת כמו HashMap ?

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.