الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Pascal's Triangle Using Recursive

بدأه fatimah في 6 مارس 2009 · 2 رد · 669 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي واجب مو عارفة كيف ابدأ فيه

فكرة حله او طريقة حله موعارفة له

حد عنده اي فكرة اكون شاكرة جدا

ملاحظة:

انا مو طالبة حد يحل الواجب عني

انا اطلب يد العون والمساعدة في طريقة حله

السؤال هو:

Write a program, that computes and prints out the coefficients of Pascal’s triangle for the first n rows. Start by writing a recursive function, int C(m,n) that computes C(m,n) recursively. It should make use of the following formula: 
C(m,0) = 1 and C(m, m) = 1 for m >= 0. 
C(m,n) = C(m-1, n-1) + C(m-1, n) for m > n > 0. 
First, write your main function to test your C(m,n) function with several different values of m and n (remember to keep n <= m). 
Your program should be able to print out the Pascal triangle until first n rows, where n is being entered by the user.

ومثال لشاشة البرنامج

Enter number n: 3 [Enter]
Result:
1 
1 1
1 2 1
1 3 3 1

Enter number n: 4 [Enter]
Result:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

ومشكوريـــــــن

#2

هذا كود يحتاج الي قليل من التعديل:

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fact(const int i)
  5. {
  6. return ((i>1)?i*fact(i-1):1);
  7. }
  8. int c(const int n,const int k)
  9. {
  10. return(fact(n)/(fact(k)*fact(n-k)));
  11. }
  12.  
  13. void pascal( int n)
  14. {
  15. static int i=0;
  16. if(i<=n)
  17. {
  18. cout<<c(n,i++)<<" "; pascal(n);
  19. }
  20. else if(n>=0)
  21. {
  22. --n;i=0;cout<<endl; pascal(n);
  23. }
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32. pascal(7);
  33. return 0;
  34. }
  35.  

tvquran_6.gif

#3

يااخ فهد انا اشكررررررك

سادرس الكود واعدله بطريقتي

شكرا اخي

مواضيع مشابهة