![photo](/responsive_image/150/150/0/0/0/cache/matlabcentral/profiles/5389074_1522108019944_DEF.jpg)
prasanta sahoo
SOA University
Followers: 0 Following: 0
Student
Feeds
提问
Write a function called one_per_n that returns the smallest positive integer n for which the sum 1 + 1/2 + 1/3 + … + 1/n , is greater than or equal to x where x is the input argument. Limit the maximum number n of terms in the sum to 10,000 .
function out=one_per_n(x) if x>10000 out=-1; %fprintf('-1\n'); else total=0; for n=1:x; total=(total+(1/n)); end if...
9 years 前 | 5 个回答 | 0