1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Programming in C - Kinda stuck

Discussion in 'C' started by PEANUTS, Oct 13, 2006.

  1. PEANUTS

    PEANUTS New Member

    Joined:
    Oct 13, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    The idea:
    Using looping methods and the IF constrcut to print the numbers between 1 and 10 along with an idications of whether each is even or odd. Like this

    1 is odd
    2 is even
    3 is odd

    Using C

    My attempt:

    /* Name:

    Cameron Owen
    CIC Y1 G1
    Software Development
    Mathmatics

    */
    Code:
    #include <stdio.h>
    void main (void)
    
    {
    int iCount;                     //decalered integar variable
    iCount=1;					//assigning 1 to iCount
    clrscr();
    				do{
    				printf("%d",iCount);
    
    					if(iCount, "%/2==0");
    					printf ("EVEN\n");
    					else
    					printf ("ODD\n");
    
    					iCount++;
    				  }while(iCount<11);
    getch();
    }
    i understand the basic idea for C but require further assisance. This only gives one error. Else is misplaced.
    I know there are other ways to do this without the need to use a maths division but that would only work for the numbers i choose.

    My idea is, if a number is divisable by 2 and gives a remainder 0. Then its even
    If a number is divisable by 2 and gives a remiander 1. It is odd


    Many thanks if you help me on this,

    Cameron
     
    Last edited by a moderator: Oct 15, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Just replace the dowhile loop with the following

    Code:
    do{
    	printf("%d",iCount);
    	
    	if(iCount%2==0)
    		printf ("EVEN\n");
    	else
    		printf ("ODD\n");
    	
    	iCount++;
    }while(iCount<11);
    
     

Share This Page