Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Check Odd or Even Number Without Using Any Condition and Loops

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-11-2009
Member
 
Join Date: Nov 2008
Posts: 68
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.
Reply With Quote
  #2  
Old 30-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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]);		
	}
}
Reply With Quote
  #3  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
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();
}
Reply With Quote
  #4  
Old 30-11-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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();
}
Reply With Quote
  #5  
Old 30-11-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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);
    }
  }
}
Reply With Quote
  #6  
Old 28-03-2010
Member
 
Join Date: Mar 2010
Posts: 1
smile 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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:23 AM.