עבור לתוכן
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

פורסם

זה תרגיל שאני מנסה לעשות כי יש לי בגרות ביום חמישי, תרגיל שמצאתי והוא ממש קשה:

הגדר פונקציה / תת-תוכנית / פעולה רקורסיבית בשם printit שתדפיס רשימה של מספרים שלמים. בשורה הראשונה תודפס המספר n בשורה השנייה המספר 2n ובשורה השלישית 4n וכן הלאה עד שיעבור ערך של 5767. לאחר מכן יודפס אותו רשימה בסדר הפוך עד ל-n.

לדוגמא עבור n=790 אזי יודפס

790

1580

3160

6320

6320

3160

1580

790

פורסם

:xyxthumbs:בבקשה , אם אתה צריך הסבר למה וכמה תרגיש חופשי



using System;
using System.Collections.Generic;
using System.Text;

namespace recurs
{
class Program
{
static int num;
static void Main(string[] args)
{
Console.WriteLine("Enter a Number For Test");
num = int.Parse(Console.ReadLine());
Console.WriteLine();
printit(num);
Console.ReadLine();
}

private static void printit(int number)
{
Console.WriteLine(number);
if (number > 5767)
{
Console.WriteLine(number);
}
else
{
printit(2 * number);
Console.WriteLine(number);
}
}

}
}

פורסם
  • מחבר

:xyxthumbs:בבקשה , אם אתה צריך הסבר למה וכמה תרגיש חופשי



using System;
using System.Collections.Generic;
using System.Text;

namespace recurs
{
class Program
{
static int num;
static void Main(string[] args)
{
Console.WriteLine("Enter a Number For Test");
num = int.Parse(Console.ReadLine());
Console.WriteLine();
printit(num);
Console.ReadLine();
}

private static void printit(int number)
{
Console.WriteLine(number);
if (number > 5767)
{
Console.WriteLine(number);
}
else
{
printit(2 * number);
Console.WriteLine(number);
}
}

}
}

וואו פיתרון כזה פשוט.. פאק..

תודה ענקית, נראה לי הבנתי תעיקרון.

פורסם

למה שאלות כאלו נותנים בC# (או שכל הבחינה בנושאי תכנות היא בשפה הזו) ?

פורסם

כי הבגרות במדעי המחשב היא בדיחה אחת גדולה.

ארכיון

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

דיונים חדשים

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.