Thread: Collatz Conjecture

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Collatz Conjecture

    Hey all. I am curious about this code and where the mistake is:

    Code:
    #include
    
    int main(void)
    {
    int n;
    printf("Enter a number for n: \n")
    scanf("%i",  &n)'
    f(n);
    
    
    int collat(int);
    int collat(int n)
    	{
    	int iterations =0;
    	while (n != 1) 
    	{
    	if (n%1==0)
    	{
    	n /=2
    	}
    	else
    	{
    	n = 3*n +1;
    	iterations ++;
    	}
    	}
    int(int n)
    	{
    	int count = 0;
    	int sum = 0;
    	int temp;
    	while(count < n)
    		{
    		scanf("%i", &temp);
    		sum += (collat)temp;
                                    count++;
    		printf("Average iterations= %i\n", (float)sum);
    		}
    
    	}
    return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    There are lots of mistakes...

    1) There are function definitions inside your main procedure.
    2) Ther are numerous syntax errors.
    3) You cannot typecast to a function name.
    4) You cannot use type names as function names
    5) You cannot create nameless functions

    You need to work with your compiler error messages and work them out one at a time.
    You should also review your book/lesson/tutorial on program structure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Goldbach's Conjecture
    By cashmerelc in forum C Programming
    Replies: 7
    Last Post: 07-19-2010, 10:41 PM
  2. Help With Collatz Conjecture
    By Dougal in forum C Programming
    Replies: 3
    Last Post: 10-20-2009, 10:01 PM
  3. Goldbach's conjecture
    By dcwang3 in forum C Programming
    Replies: 10
    Last Post: 10-14-2008, 01:34 AM
  4. Godbach conjecture!!
    By Leojeen in forum C Programming
    Replies: 10
    Last Post: 04-20-2008, 06:42 PM
  5. Goldbach Conjecture
    By StarOrbs in forum C++ Programming
    Replies: 19
    Last Post: 03-17-2005, 04:42 PM