[right] rectangle sum을 사용하는 통합 프로그램에서 작업하고 있습니다. 나는 a = 1로 바인딩 된 시작을 사용하고 'n'을 직사각형의 #으로 사용하고 'inc'를 z를 증가시키는 증가로 사용합니다.통합 프로그램의 루프 및 함수
가 어떻게 함수 f이의 (X) = X^5 + 10을 사용합니까 :
#include <iostream> #include <cmath> using std::cout; using std::endl; using std::cin; int main(){ int n; float b; float z; z=((b-1)/n); float inc; float new_sum; float sum; int decision; cout << "Would you like to calculate an area? " << endl; cout << "Enter 1 for yes, 0 for no: " << endl; cin >> decision; cout << "Please enter the number of rectangles you would like to use: " << endl; cin >> n; cout << "Please enter the upper bound of integration: " << endl; cin >> b; for (inc=0; inc < b; inc++){ new_sum=z*(f(1+(inc*z))); sum=sum+new_sum; } cout << sum << endl; return 0; }
나는 두 가지 질문이있다 : 여기에 지금까지 가지고있는 코드는? for 루프에서 어떻게 입력하고 포맷해야하는지 잘 모르겠습니다.
for 루프를 사용하여 첫 번째 질문 시퀀스를 반복 하시겠습니까? 예를 들어 1을 입력 할 때까지 반복하십시오 (while 루프를 사용하여이를 수행하는 방법을 알고 있습니다. 하지만이 for 루프와 함께 할 것입니다 궁금 해서요?)
'for' 루프가 경우에 이상적이다. for (;;)'while ()'과 동일하지만 더 혼란 스럽습니다. –
'pow (x, 5)'와'for (;;)를 시도 했습니까? –