![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2008
Posts: 10
Rep Power: 0
![]() |
C Code
Hey guys, here's a question I have. I've not taken C or C++, but I have had Fortran. Any help in corrections would be appreciated:
Question: Develop the code to compute the sum of integers from 1 to 10,000? Here is what I have: int sum = 0, i; for( i = 1; i <= 10000; i++ ) { sum = sum + i; } printf( "The sum of integers 1-10000 is: %d", sum ); |
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 655
Rep Power: 4
![]() |
Re: C Code
With actually saving it to a file and compiling, the code you posted looks correct.
There is a better way, though. Does that help at all? If you have trouble translating the arithmetic to C, post your problem and we'll try to help. ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#3 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1
![]() |
Re: C Code
what equation is that? dont know math
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Aug 2008
Posts: 10
Rep Power: 0
![]() |
Re: C Code
Thanks so much, Jess. Yeah it makes sense, I actually used that fact in writing my program in Fortran!
|
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 591
Rep Power: 5
![]() |
Re: C Code
That big thing that looks like an E, or a sideways W, or a sideays M, maybe even a C, that's the Greek letter Sigma, its used in math to denote summation: http://en.wikipedia.org/wiki/Summation
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#6 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1
![]() |
Re: C Code
which is equal to n(n+1)/2 . . . . ill look for the proof... hehehehe
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Incorporating javascript code into java application | csrocker101 | Java | 1 | Feb 11th, 2008 7:36 AM |
| Viewing VB's Automated code | john Wesley | Visual Basic .NET | 3 | Jun 8th, 2006 6:37 AM |
| FTP and return code fetching | Serinth | C | 2 | May 29th, 2006 12:05 AM |
| String to Morse Code - Copying from string to string | Xenon | C | 29 | Nov 10th, 2005 3:30 PM |
| Help with code please | LiverLad | Java | 0 | Feb 9th, 2005 11:36 AM |