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

ارجو المساعدة

بدأه ryoko في 29 أكتوبر 2008 · 9 رد · 522 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بســم الله الـرحمــن الرحيــم

السلام عليكــم ورحمـة الله وبركاتــة

أنا أدرس في بريطانيا قسم

ICCT

وناخذ برنامج

C++

وطلبوا مننا هذا

Project 3 – Fibonacci Series

Modify your program further to add a third option – the Fibonacci Series. As before, you need to ask for the number of values to display.

The Fibonacci Series is a series of numbers which starts with 1, 1 and then each number is the sum of the previous two. For example,

1, 1, 2, 3, 5, 8, 13, 21, 34, 55

Quick Hint: The loop should start from the third number onwards – otherwise you can't compute the sum of the previous two numbers.

Project 4 – The Golden Ratio

Modify your Fibonacci Series to display the ratio of each pair of numbers – it doesn't matter whether you divide the first by the second or vice-versa.

What do you notice about this ratio? Does it look like its converging to a particular number?

(Anyone who has seen/read the DaVinci Code should recognise this)

اوكي انا اشتغلت عليه و طلعت الكود الي هو اتاشمنت ممكن تتطلعون عليه

#include <stdlib.h>

#include <stdio.h>

#include <iostream>

int main()

{

char line[40];

int choice;

int numNumbers, interval;

int count, result, sum;

int result2, last, next, sum1;

float ratio;

printf( "Please choose which number series you would like to display:\n" );

printf( " 1. Arithmetic Series\n" );

printf( " 2. Factorial Series\n" );

printf( " 3. Fibonacci Series\n" );

gets( line );

choice = atoi( line );

if( choice == 1 )

{

/* We are going to do a simple geometric series */

printf( "How many numbers do you want?\n" );

gets( line );

numNumbers = atoi( line );

printf( "Please enter the interval:\n" );

gets( line );

interval = atoi( line );

count = 1;

result = 1;

sum = 0;

while( count <= numNumbers )

{

printf( "Number %3d is %d\n", count, result );

sum = result + sum;

result = result + interval;

count = count + 1;

}

printf( "Number sum is %d\n", sum );

}

else if (choice == 2 )

{ printf( "How many numbers do you want?\n" );

gets( line );

numNumbers = atoi( line );

count = 1;

result2 = 1;

while ( count <= numNumbers )

{

printf( "Number %3d is %d\n", count, result2 );

count = count + 1;

result2 = count * result2;

}

}

else if (choice == 3)

{ printf( "How many numbers do you want?\n" );

gets( line );

numNumbers = atoi ( line );

next = 0;

last = 1;

count = 1;

while ( count <= numNumbers )

{

sum1 = next + last;

printf( "Number %3d is %d\n", count, sum1 );

next = last;

last = sum1;

ratio = sum1/next;

count = count + 1;

printf( " The ratio is %.2f\n", ratio);

}

}

else

{

printf( "You entered an invalid choice.\n" );

}

return( 0 );

}

طيب ممكن تتاكدولي او احد يساعدني الكود ما يطلع اي

error

والحمدالله لكن مو الجواب الي انا ابي انا ابي يطلع الراشيو ارقام و معاها كسور بس يطلعلي ارقام و جنبها اصفار ممكن مساعدة بس تعرفوني وين الغلط في الكود وشكرا

تم تعديل هذه المشاركة بواسطة ryoko في 30 أكتوبر 2008 في 00:10

uaekeys27.jpg
#2

السلام عليكم:

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. //#include <iostream>
  5.  
  6. int main()
  7. {
  8. char line[40];
  9. int choice;
  10. int numNumbers, interval;
  11. int count, result, sum;
  12. int result2, last, next, sum1;
  13. float ratio;
  14.  
  15. printf( "Please choose which number series you would like to display:n" );
  16. printf( " 1. Arithmetic Seriesn" );
  17. printf( " 2. Factorial Seriesn" );
  18. printf( " 3. Fibonacci Seriesn" );
  19. gets( line );
  20. choice = atoi( line );
  21.  
  22. if( choice == 1 )
  23. {
  24. /* We are going to do a simple geometric series */
  25. printf( "How many numbers do you want?n" );
  26. gets( line );
  27. numNumbers = atoi( line );
  28. printf( "Please enter the interval:n" );
  29. gets( line );
  30. interval = atoi( line );
  31.  
  32. count = 1;
  33. result = 1;
  34. sum = 0;
  35. while( count <= numNumbers )
  36. {
  37. printf( "Number %3d is %dn", count, result );
  38. sum = result + sum;
  39. result = result + interval;
  40. count = count + 1;
  41.  
  42. }
  43. printf( "Number sum is %dn", sum );
  44. }
  45. else if (choice == 2 )
  46. { printf( "How many numbers do you want?n" );
  47. gets( line );
  48. numNumbers = atoi( line );
  49. count = 1;
  50. result2 = 1;
  51.  
  52. while ( count <= numNumbers )
  53. {
  54. printf( "Number %3d is %dn", count, result2 );
  55. count = count + 1;
  56. result2 = count * result2;
  57. }
  58.  
  59. }
  60. else if (choice == 3)
  61. { printf( "How many numbers do you want?n" );
  62. gets( line );
  63. numNumbers = atoi ( line );
  64.  
  65. next = 0;
  66. last = 1;
  67. count = 1;
  68. while ( count <= numNumbers )
  69. {
  70. sum1 = next + last;
  71. printf( "Number %3d is %dn", count, sum1 );
  72. next = last;
  73. last = sum1;
  74. ratio =(float)sum1/next;
  75. count = count + 1;
  76. printf( " The ratio is %.2fn", ratio);
  77. }
  78. }
  79. else
  80. {
  81. printf( "You entered an invalid choice.n" );
  82. }
  83.  
  84. return( 0 );
  85. }
  86.  
  87.  

tvquran_6.gif

#3

شكرا اخوي طيب لو سمحت الحين في الفابرونيك نمبرز يطلعلي 1,2,3,5

وانا ابيه يطلعلي 1,1,2,3,5

كيف ممكن اعدله من جد حاولت بكل الطرق و مو راضي

uaekeys27.jpg
#4

واخوي فهد طيب ليش انت عرفت ال ratio

مرتين مو انا معرفتها فوق انا درست جافا و ممكن تتعرف مرة وحدة و خلاص في برنامج الجافا في فرق بين ال C++

و الجافا ؟؟

uaekeys27.jpg
#5

أذا تقصد هذا السطر

  1. ratio =(float)sum1/next;
  2.  

فهو طريقة للتحويل من صحيح الي عشري

tvquran_6.gif

#6

انا عارفة انها طريقة لتحويل العدد الصحيح الى عشري بس لو تشوف الكود انا معرفته من اول

لو تشوف الكود من اول معرفته

float ratio;

هل لازم نعرفه مرة ثانية؟

uaekeys27.jpg
#7

هو يحول حاصل القسمة الي عشري.

sum1/next يكون عدد صحيح اصلا .

لكن بالطريقة السابقة حولت sum1 الي عشري فيكون ناتج القسمة عشري.

لان صحيح على صحيح يعطي صحيح.

tvquran_6.gif

#8

اها يعطيك الف الف عافية اخوي و يوفقك رب العباد في دنياك و اخرتك

عندي بروجكت ثاني ان شاء الله راح احاول فيه و اكتبه وان لقيت صعوبة راح احط السؤال مع محاولاتي لحله

و شكرا والله ماني عارفة كيف اشكرك

الله يجزاك الف خير

uaekeys27.jpg
#9
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <iostream>
  5.  
  6. void ArithmeticSeries()
  7. {
  8. char line[41];
  9. int numNumbers, interval;
  10. int count, result = 1, sum = 0;
  11.  
  12. printf("n1. Arithmetic Series:n");
  13. printf("=====================n");
  14.  
  15. printf("How many numbers do you want?: ");
  16. numNumbers = atoi(gets(line));
  17.  
  18. printf("Please enter the interval: ");
  19. interval = atoi(gets(line));
  20.  
  21. for(count=1; count<=numNumbers; count++)
  22. {
  23. printf("[Number %03d] is %dn", count, result);
  24. sum += result;
  25. result += interval;
  26. }
  27. printf("<Number sum> is %dn", sum);
  28. }
  29.  
  30. void FactorialSeries()
  31. {
  32. char line[41];
  33. int numNumbers;
  34. int count, result = 1;
  35.  
  36. printf("n2. Factorial Series:n");
  37. printf("====================n");
  38.  
  39. printf("How many numbers do you want?: ");
  40. numNumbers = atoi(gets(line));
  41.  
  42. for(count=1; count<=numNumbers; count++)
  43. {
  44. printf("[Number %03d] is %dn", count, result);
  45. result *= count;
  46. }
  47. }
  48.  
  49. void FibonacciSeries()
  50. {
  51. char line[41];
  52. int numNumbers;
  53. int next, current = 1, last = 0;
  54. int count;
  55. float ratio;
  56.  
  57. printf("n3. Fibonacci Series:n");
  58. printf("====================n");
  59.  
  60. printf("How many numbers do you want?: ");
  61. numNumbers = atoi(gets(line));
  62.  
  63. /* next = last + current */
  64. /* 0, 1, 1, 2, 3, 5, 8 */
  65. /* */
  66. /* 0, 1, last, current, next */
  67. /* 0, 1, 1, last, current, next */
  68. /* 0, 1, 1, 2, last, current, next */
  69. /* 0, 1, 1, 2, 3, last, current, next */
  70.  
  71. for(count=1; count<=numNumbers; count++)
  72. {
  73. next = last + current;
  74. ratio = (float)last/(float)current;
  75.  
  76. printf("[Number %03d] is %6d, The ratio is %.2fn", count, current, ratio);
  77. last = current;
  78. current = next;
  79. }
  80. }
  81.  
  82. int main()
  83. {
  84. int choice;
  85.  
  86. do
  87. {
  88. printf("nMain Menu:n");
  89. printf("==========n");
  90. printf("Please choose which number series you would like to display:n");
  91. printf(" 1. Arithmetic Seriesn");
  92. printf(" 2. Factorial Seriesn");
  93. printf(" 3. Fibonacci Seriesn");
  94. printf(" 0. Exit [ESC]n");
  95.  
  96. printf(" Choice: ");
  97. choice = getche();
  98. printf("n");
  99.  
  100. switch(choice)
  101. {
  102. case '1':
  103. ArithmeticSeries();
  104. break;
  105.  
  106. case '2':
  107. FactorialSeries();
  108. break;
  109.  
  110. case '3':
  111. FibonacciSeries();
  112. break;
  113.  
  114. case '0':
  115. case 27:
  116. /* Exit */
  117. break;
  118.  
  119. default:
  120. printf("You entered an invalid choice... please choose [0-3]n");
  121. }
  122. }
  123. while(choice != '0' && choice != 27);
  124.  
  125. return (0);
  126. }
  127.  

تم تعديل هذه المشاركة بواسطة دحدوح في 31 أكتوبر 2008 في 04:37

#10

مشكور أخ دحدوح ماشاء الله تبارك الله

بس هل في طريقة من غير ما تغير الكود حق ال وايل لوب وانه نفس الكود حقي ما يتغير بس يتصلح

uaekeys27.jpg

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