ممكن مساعدة االله يسعدكم .....
هنا السؤال عن تصحيح الكود ليش مايطلع out put?/
23. The following while loop should print the product of the odd integers between 0 and 10, inclusive.
1 int product = 1, i = 0;
2
3 while ( i <= 10 )
4 {
5 if ( i % 2 != 0 )
6 i *= product;
7
8 product++;
9 }
10
11 System.out.printf( "The product is: %d\n", product );
Your answer:
|
تفضلي الحل
طبعا انا مختصرة ، product = pro
شوفي التعديلات ،
في غلطتين ،
الأولى انوآ البرودكت هو اللي المفروض يتأثر بالمعادلة المضروبة وليسـت i
و الـ i هي اللي تزدآد بمقدار 1 ، increment علشان يرجع يختبرها مره ثانية
،
طبعا هنا المطلوب (ناتج ضرب جميع الأعداد الفردية بين 0-10)
كود:
;int pro = 1 , i = 0
while (i<= 10)
{if (i%2 != 0)
pro *=i ;
i ++ ;
}
System.out.printf("the product is :\n %d",pro);
}
}