/*-*-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 : 2. You may use the result from the above question (or not) (b) Write a function called g which takes an integer n as an argument and returns an integer which satisfies the following conditions: a. if the argument n is odd return 3*n+1 b. if the argument n is even return n/2 Put the function g in c source file called "test.c", add a main to print out g(n) for all n from 1 to 100. Submit source and hard copy. ***************************************************************************/ /* Inlcude section. */ #include <stdio.h> int g (int ); /*************************************************************************** Function : main Author : Jeremy Russell Date : September 5, 2002 Description : Processes the number 1 through 100, inclusive through function 'g'. Arguments : void Returns : N/A Notes : None See Also : None ***************************************************************************/ int main ( void ) { /* Vatiable declaration. */ int iterate; int value; /* Main body. */ for ( iterate = 1; iterate <= 100; iterate++) { value = iterate; while ( value != 1) { value = g( value ); printf ("The beginning function 'g ( %d )' eventually retruns the number: %d\n", iterate, value); } } return 0; } /*************************************************************************** Function : g Author : Jeremy Russell Date : September 5, 2002 Description : If the number is Arguments : Integer Returns : integer Notes : None See Also : None ***************************************************************************/ int g ( int number ) { if ( number % 2 ) { return 3 * number + 1; } else { return number / 2; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 2117 | Jeremy Russell |
Project 1 nsplit.c has problesm still. |