CrazyEngineers
  • techno_ishant
    techno_ishant

    MemberDec 1, 2009

    Even/Odd Program in C

    write an program in C to find whether a given input number is EVEN or ODD
    Condition :- do not use conditional statement(if,while) ,ternary operator(?)
    only use printf and scanf statement and arithmetic operator .
    Example: input : Enter number- 22
    output : Even
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • cooltwins

    MemberDec 1, 2009

    diclaimer:i am no computer genius. i just did c during 1st year and here is my idea...😀
    #include<stdio.h>
    void main()
    {
    printf("\n enter the number:");
    scanf("%d",&n);
    int l=0;
    l=n%2;
    for(;l=0; )
    printf("\n EVEN");
    for(;l=1; )
    printf("\n ODD");
    }

    this is prone to errors....
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberDec 1, 2009

    #include<iostream.h>
    #include<conio.h>
    char *a[2]={"even","odd"};
    int no;
    cin>>no;
    cout<<a[no%2]<<"no";
    }
    You can convert it into c language
    Are you sure? This action cannot be undone.
    Cancel
  • raj87verma88

    MemberDec 2, 2009

    @Techno: Do you mind sharing your own attempt at solving this question? It looks as if you want us to solve some assignment question for you. We do not tolerate this here.

    @Cooltwin and Goyal: We do not provide free lunches. We help others but do not spoon feed the answers to them.
    Are you sure? This action cannot be undone.
    Cancel
  • techno_ishant

    MemberDec 2, 2009

    ya i'll raj... i have given this program in national level technical event held in over institute
    and no one have solve this program
    so here it is:-

    main()
    {
    char *str[2]={"EVEN","ODD"};
    int num;
    printf("Enter Number :-");
    scanf("%d",&num);
    printf("%s",str[num%2]);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • mohammad yusuf

    MemberFeb 9, 2011

    ishan sir i have tried this code but didn't find the solution it has error in scanf statement
    #include<stdio.h>
    void main()
    {
    printf("\n enter the number:");
    scanf("%d",&n);
    int l=0;
    l=n%2;
    for(;l=0; )
    printf("\n EVEN");
    for(;l=1; )
    printf("\n ODD");
    }
    Are you sure? This action cannot be undone.
    Cancel
  • suyash

    MemberFeb 22, 2011

    techno_ishant
    ya i'll raj... i have given this program in national level technical event held in over institute
    and no one have solve this program
    Umm... I am not too sure that no one was able to solve this program if it was indeed a national level technical event 😀
    Are you sure? This action cannot be undone.
    Cancel
  • suyash

    MemberFeb 22, 2011

    mohammad yusuf
    ishan sir i have tried this code but didn't find the solution it has error in scanf statement
    I guess the html encoding used in CE forums have goofed up the ampersand operator in the scanf statement. You should have at least edited the code before running it just like that by copy paste 😀
    P.S.:- after editing the scanf statement, you might get one more error where the code is trying to divide the int variable by 2. 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register