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

[עזרה]בבניית תוכנית פיבונאצ'י

Featured Replies

פורסם

נתון לי שA1=0

ו A2=1

ואני צריך להדפיס בלולאה את 10 המספרים הראשונים בסדדרה

"כתוב תכנית המדפיסה את 10 האיברים הראשונים של הסדרה(פיבונא'צי. נתון .A(1)=0; A(2)=1"

"

פורסם

שפה?

בעיקרון אתה מחבר כל פעם שני איברים ומכניס למשתנה שלישי. לאחר שאתה מדפיס אותו, אתה מעביר את תוכן המשתנה השני למשתנה הראשון, ואת תוכן השלישי למשתנה השלישי וממשיך ככה.

A1=0;

A2=1;

A3=A1+A2; //A3=1

A1=A2; //A1=1

A2=A3; //A2=1

A3=A1+A2;

וכך הלאה. לולאת FOR תעשה את העבודה יופי.

מימוש ב C#:


int a1=0;
int a2 =1;
int a3;
Console.WriteLine(a1);
Console.WriteLine(a2);
for (int i = 0; i < 8; i++)
{
a3 = a1 + a2;
Console.WriteLine(a3);
a1 = a2;
a2 = a3;
}
Console.Read();

פורסם

זה די פשוט.. כל איבר בסדרה הוא סכום של שני האיברים הקודמים לו.

הנה תוכנית מלאה ב-CPP שעושה את זה:


#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
int current_num=1, prev_num=1;
int n=10;
for (int i=1;i<n;i++)
{
int new_num = current_num+prev_num;
prev_num=current_num;
current_num=new_num;
cout << current_num<<endl;
}
system("PAUSE");
return 0;
}

ארכיון

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

דיונים חדשים

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.