15,946,158 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Find maximun range of an array Member 135010212-Nov-17 22:35 Member 13501021 2-Nov-17 22:35
 Re: Find maximun range of an array David Crow3-Nov-17 3:51 David Crow 3-Nov-17 3:51
 Re: Find maximun range of an array Sascha Lefèvre3-Nov-17 4:22 Sascha Lefèvre 3-Nov-17 4:22
 Re: Find maximun range of an array Sascha Lefèvre3-Nov-17 14:17 Sascha Lefèvre 3-Nov-17 14:17
 Calculate sum of M natural numbers starting from N. Member 134789861-Nov-17 9:16 Member 13478986 1-Nov-17 9:16
 Re: Calculate sum of M natural numbers starting from N. Victor Nijegorodov1-Nov-17 9:49 Victor Nijegorodov 1-Nov-17 9:49
 Re: Calculate sum of M natural numbers starting from N. Member 134789861-Nov-17 10:19 Member 13478986 1-Nov-17 10:19
 Re: Calculate sum of M natural numbers starting from N. CPallini1-Nov-17 10:53 CPallini 1-Nov-17 10:53
 You need no iteration, actually. Since (see 1 + 2 + 3 + 4 + ⋯ - Wikipedia[^]) `1 + 2 + ... + n = n * (n + 1) / 2` In your case `SUM = ((N + M - 1) * (N + M) - (N - 1) * (N)) / 2` Let's try the formula with the input `N=3, M=4` `SUM = ((3 + 4 -1) * (3 + 4) - (3) * (2)) / 2 = (6 * 7 - 3 * 2) / 2 = (42 - 6) / 2 = 18`
 Re: Calculate sum of M natural numbers starting from N. Member 134789861-Nov-17 10:57 Member 13478986 1-Nov-17 10:57
 [win32] sprite error ? bluatigro1-Nov-17 3:03 bluatigro 1-Nov-17 3:03
 Re: [win32] sprite error ? Richard MacCutchan1-Nov-17 3:18 Richard MacCutchan 1-Nov-17 3:18
 Re: [win32] sprite error ? Jochen Arndt1-Nov-17 3:26 Jochen Arndt 1-Nov-17 3:26
 Re: [win32] sprite error ? David Crow1-Nov-17 3:32 David Crow 1-Nov-17 3:32
 Re: [win32] sprite error ? bluatigro2-Nov-17 0:13 bluatigro 2-Nov-17 0:13
 Re: [win32] sprite error ? bluatigro2-Nov-17 1:01 bluatigro 2-Nov-17 1:01
 Re: [win32] sprite error ? Richard MacCutchan2-Nov-17 1:46 Richard MacCutchan 2-Nov-17 1:46
 Re: [win32] sprite error ? bluatigro3-Nov-17 0:09 bluatigro 3-Nov-17 0:09
 Re: [win32] sprite error ? Richard MacCutchan3-Nov-17 0:28 Richard MacCutchan 3-Nov-17 0:28
 Re: [win32] sprite error ? bluatigro7-Nov-17 22:36 bluatigro 7-Nov-17 22:36
 Re: [win32] sprite error ? Richard MacCutchan7-Nov-17 22:45 Richard MacCutchan 7-Nov-17 22:45
 [win32] VR double buffering ? bluatigro31-Oct-17 4:24 bluatigro 31-Oct-17 4:24
 Re: [win32] VR double buffering ? David Crow31-Oct-17 8:01 David Crow 31-Oct-17 8:01
 Re: [win32] VR double buffering ? Richard MacCutchan31-Oct-17 22:40 Richard MacCutchan 31-Oct-17 22:40
 Re: [win32] VR double buffering ? bluatigro1-Nov-17 0:37 bluatigro 1-Nov-17 0:37
 Re: [win32] VR double buffering ? Richard MacCutchan1-Nov-17 1:03 Richard MacCutchan 1-Nov-17 1:03
 Last Visit: 31-Dec-99 18:00     Last Update: 23-Jul-24 19:36 Refresh ᐊ Prev1...332333334335336337338339340341 Next ᐅ