/*-*-mode:c-*- *************************************************************************** CSN381: Project 1 (2:a) http://homepage.mac.com/hteric/Project1.pdf *************************************************************************** File : sumofodd.c Author : Jeremy Russell Date : September 5, 2002 Description : You may use the result from the above question (or not) (a) Write a program which compute the sum of all odd integers between (and include) 1 and 1000. This program should be called 'sumofodd.c', submit source and hard copy. ***************************************************************************/ /* Inlcude section. */ #include <stdio.h> int isodd ( int ); /*************************************************************************** Function : main Author : Jeremy Russell Date : September 5, 2002 Description : Main function of the sumofodd program. Prints the sum of all odd numbers bewteen 1 and 1000, inclusive. Arguments : void Returns : void Notes : None See Also : None ***************************************************************************/ int main ( void ) { /* Vatiable declaration. */ int iterate; long int sum = 0; /* Main body. */ for ( iterate = 1; iterate <= 1000; iterate++) { if ( isodd( iterate ) ) sum = iterate + sum; } printf ("The sum of all odd numbers between 1 and 1000, inclusive, is: %ld\n", sum); return 0; } /*************************************************************************** Function : isodd Author : Jeremy Russell Date : September 5, 2002 Description : Evaluate an integer to seeif it is odd. Arguments : * int number Returns : true or false (0 || 1) Notes : None See Also : None ***************************************************************************/ int isodd ( int number ) { return number % 2; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 2117 | Jeremy Russell |
Project 1 nsplit.c has problesm still. |
||
#1 | 2115 | Jeremy Russell | Project 1, 2a |