|
| |||||||||
| Tags: condition, even, loops, number, odd |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Check Odd or Even Number Without Using Any Condition and Loops
Hi friends, in my college We have given one question related to programming and I am not able to solve it. Can anyone help me in this problem? I need just logic of that particular program and that's it. Please, help me in this. The question is Find Out the given number is odd or even, without the use of any condition and loops. |
|
#2
| ||||
| ||||
| Re: Check Odd or Even Number Without Using Any Condition and Loops
Hi, I think this will help you. I have created below code in java which Check Odd or Even Number Without Using Any Condition and Loops. Just make use of it. Code: import java.io.*;
public class EvenOrOdd
{
public static void main(String arg[])throws IOException
{
String arr[]={"Even","Odd"};
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num;
System.out.println("Enter number to chcek");
num=Integer.parseInt(br.readLine());
num=num%2;
System.out.println("Entered number is "+arr[num]);
}
} |
|
#3
| |||
| |||
| Re: Check Odd or Even Number Without Using Any Condition and Loops
Hi, I have code for you in C language, which will Check Odd or Even Number Without Using Any Condition and Loops. Try to use it. Code: void main()
{
int number;
char sarr[]={"even","odd"};
printf("Enter the no.:");
scanf("%d",&number);
number=number%2;
printf("the number you have entered is %s",sarr[number]);
getch();
} |
|
#4
| ||||
| ||||
| Re: Check Odd or Even Number Without Using Any Condition and Loops
Hi, I don't know how to check the number is even or odd without using any condition or loop, but I have a solution given in my book, you can use it for your purpose. Code: void main()
{
int n;
char *s[4]={"even","odd"};
printf("Enter the no.:");
scanf("%d",&n);
n=n%2;
printf("th no. is %s",s[n]);
getch();
} |
|
#5
| ||||
| ||||
| Re: Check Odd or Even Number Without Using Any Condition and Loops
Hi, I don't know how to check odd or even number without using any condition or loop, I have done this with the help of loop. I am sending this, then just develop your logic and use it. Code: import java.io.*;
public class EvenOdd
{
public static void main(String[] args) throws IOException
{
try
{
int n;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(in.readLine());
if (n % 2 == 0)
{
System.out.println("Given number is Even.");
}
else
{
System.out.println("Given number is Odd.");
}
}
catch(NumberFormatException e){
System.out.println(e.getMessage() + " is not a numeric value.");
System.exit(0);
}
}
} |
|
#6
| |||
| |||
Re: Check Odd or Even Number Without Using Any Condition and Loops
#include<stdio.h> #define bind(k,i,n,d) n##k int main() { int n; printf("Enter the number:"); scanf("%d",&n); bind(f,a,i,l)(n%2==0) { printf("Even\n"); exit(0); } printf("Odd\n"); return 0; } |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Check Odd or Even Number Without Using Any Condition and Loops" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check IMEI number of iPhone | Elbanco | Portable Devices | 6 | 23-01-2010 03:49 AM |
| How to check China mobile IMEI number ? | depesh | Portable Devices | 9 | 01-01-2010 06:45 PM |
| How to check input if it is number or not? | Linoo | Software Development | 3 | 24-11-2009 04:46 PM |
| How to check if a number belongs to a column or not in Excel | $tatic | Software Development | 4 | 07-04-2009 10:45 PM |
| Check whether an integer is a prime number in C | Projectkmo | Software Development | 2 | 08-10-2008 07:27 PM |