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

פורסם

אפשר הסבר איך זה הולך החישוב

של העצרת הזאת?

x! = x * (x-1) * (x-2) * (x-3) * ... * (2) * 1

וזה יכול להרשם ככה

x! = x * (x-1)!

פורסם

אני מניח כאן שאתה מתכוון לסדר הקריאות, בנוסף לא כתבת את הפונקציה הנתונה לך בC, אבל נניח שהיא נראית ככה:

int fact(int n){

if(n==1){return 1;}

return n*fact(n-1);

}

נקח לדוגמה את חישוב העצרת של 3, סדרת הקריאות תראה בערך ככה (עובר לאנגלית מסיבות של ישור טקסט):

Argument --> line in code

fact(3) --> return 3 * fact(2) //Now fact(2) is called

fact(2) --> return 2 * fact(1) //Now fact(1) is called

fact(1) --> if(n==1){return 1;} //Now we know that fact(1) = 1 and can compute fact(2), and then fact(3)

נערך על-ידי WildFire

  • 2 שבועות מאוחר יותר...
פורסם

תחשוב על משהו פשוט יותר.

הנה הגדרה רקורסיבית של כפל:


a*1 = a
a*b = a + a*(b-1)

נערך על-ידי Gil28

ארכיון

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

דיונים חדשים

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.