Help With Collatz Conjecture

This is a discussion on Help With Collatz Conjecture within the C Programming forums, part of the General Programming Boards category; ok,so i started programming yesterday,and im trying to write a code for the collatz conjecture,heres where i am Code: #include ...

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

    Help With Collatz Conjecture

    ok,so i started programming yesterday,and im trying to write a code for the collatz conjecture,heres where i am


    Code:
     #include <stdio.h>
    
    int main()
    {
    	int x
    	prinf( "Enter Number" );
    	scanf( "%d", &x );
    now how do i tell it that if x is an even integer,that i want to divide it by 2,im stuck with the even integer part.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Test the result of the value entered modulus 2 (% is the modulus operator) against 0.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Code:
    bool is_even(const int number) {
      return number % 2;
    }

  4. #4
    Registered User
    Join Date
    Sep 2009
    Location
    USA
    Posts
    63
    try this

    number%2==0 for even

    if it isnt then it is odd

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. Goldbach's conjecture
    By dcwang3 in forum C Programming
    Replies: 10
    Last Post: 10-14-2008, 01:34 AM
  3. Godbach conjecture!!
    By Leojeen in forum C Programming
    Replies: 10
    Last Post: 04-20-2008, 06:42 PM
  4. Goldbach Conjecture
    By StarOrbs in forum C++ Programming
    Replies: 19
    Last Post: 03-17-2005, 03:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21