Plz solve my problem !

This is a discussion on Plz solve my problem ! within the C Programming forums, part of the General Programming Boards category; Hello freinds can any body solve my little problem:- Make this prog in C--- Enter a number from keyboard and ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    Unhappy Plz solve my problem !

    Hello freinds can any body solve my little problem:-
    Make this prog in C---
    Enter a number from keyboard and we have to tell weather this number is odd or even without using Control statements ?

  2. #2

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    i think no one is going to code you the whole program.
    show some effort!

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    I'd make 2 giant arrays, one containing all even numbers and one containing all odd numbers. If your number is in the odd array, it's odd. If it's in the even array, it's even.

  5. #5
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    I'd probably know what one was if I saw it but as far as jargon goes, what's a control statement?

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I'd probably know what one was if I saw it but as far as jargon goes, what's a control statement?
    if, switch, while, for, etc.
    *Cela*

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    *sniff sniff* *sniff sniff* i smell homework, hmm......

  8. #8
    Registered User penney's Avatar
    Join Date
    Jan 2003
    Posts
    47

    Untested

    void main(void)
    {
    char oddeven[][5]={"even","odd");
    int number;

    printf("Enter number:");
    scanf("%d",&number);
    printf("The number %d is %s",number,oddeven[number%2]);
    }

  9. #9
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Ouch..... you guys are so harsh.

    See if this will work.

    Code:
    #include <stdio.h>
    #include <assert.h>
    
    int main(void)
    {
       int num;
    	
       printf("enter a number: ");
       scanf("%d", &num);
    	
       assert(num > 0);
    	
       printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd");
    	
       return 0;
    }
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  10. #10
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd");
    I think the ?: operator counts as a control statement, penny was on the right track.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int num;
      char *eo[] = {
        "odd",
        "even",
      };
    
      printf("Enter a number: ");
      fflush(stdout);
      
      /* Should test that sccanf works */
      /* but that means using a control statement */
      scanf("%d", &num);
      printf("%s\n", eo[num % 2 == 0]);
    
      return 0;
    }
    *Cela*

  11. #11
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Originally posted by Cela
    >>printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd");
    I think the ?: operator counts as a control statement, penny was on the right track.
    Hmph.... those picky profs
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  12. #12
    TCL
    TCL is offline
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    Code:
    #include <stdio.h>
    int main(void)
    {
      int i;
      printf("enter a number: ");
      scanf("%d", &i);
      (i%2)&&printf("The number is odd\n");
      (!(i%2))&&printf("The number is even\n");
      return 0;
    }

  13. #13
    Registered User
    Join Date
    Jan 2003
    Posts
    3

    Here

    #include <stdio.h>

    int main(void)
    {
    int InputNumber=0;
    int ReturnFunction=0;
    char junk;

    printf("Please Give Me a Number--->");
    scanf("%d", &InputNumber);

    ReturnFunction = (InputNumber%2);

    if (ReturnFunction==0)
    {
    printf("\nThe Number is Even")
    }
    else
    {
    printf("\nThe Number is Odd")
    }

    getchar(junk);

    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-14-2008, 07:17 PM
  2. count/display non-repeated element of array
    By azsquall in forum C++ Programming
    Replies: 15
    Last Post: 07-10-2008, 10:42 AM
  3. Replies: 2
    Last Post: 04-25-2005, 12:59 PM
  4. Can someone solve this problem for me?
    By hykyit in forum C Programming
    Replies: 2
    Last Post: 03-17-2005, 02:57 AM
  5. problem cant solve please help.
    By sarah in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 02:32 PM

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