top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Print “Even” or “Odd” without using conditional statement.

+1 vote
615 views
Print “Even” or “Odd” without using conditional statement.
posted Jul 2, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote
 
Best answer
#include<stdio.h>
int main()
{
        char *ptr[]={"Even","Odd"};
        int num;
        printf("Enter a number : ");
        scanf("%d",&num);
        printf("%s\n",ptr[num%2]);
        return 0;
}
answer Jul 4, 2017 by Chirag Gangdev
0 votes

odd_even[]={"Even", "Odd"};
printf("%s\n",odd_even[given_number % 2]);

answer Jul 4, 2017 by anonymous
–1 vote

We can use ternary operator.
n%2==0?printf("even"):printf("odd");

answer Jul 3, 2017 by Ibney Ali
Similar Questions
–1 vote

Given an ODD number, print diamond pattern of stars recursively.

Example
Input: n = 5,

Output:

  *
 ***
*****
 ***
  *
+2 votes

How will we print numbers from 1 to N without using loop or recursion?

+4 votes

Requirements:

1.No input should be processed, and the output should be in the form of 2 3 5 7 11 13 ... etc.
2. No reserved words in the language are used at all
3.The language should at least allow structured programming, and have reserved words (otherwise point 2 would be moot).

...