473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

find even or odd in array

#include<stdio.h>

main() {

int a;

printf("Enter a: \n");

scanf("%d", &a);


if (a % 2 == 0) {

printf("The given number is EVEN");

} else {

printf("The given number is ODD");

}

}

the above program find the even or odd but how can i find multiple of 2 for array of 100 elemens
Mar 11 '09 #1
6 9074
scruggsy
147 100+
@AsHantoosH
Any even number is a multiple of 2. No odd number is. So it looks like you already have most of the code to do this, you just need to do it inside a loop inspecting the elements of your array one at a time. If that's the part you're having trouble with, post what you've tried.

As a somewhat useless aside, another way to test if an integer is odd or even:
Expand|Select|Wrap|Line Numbers
  1. if (a & 1)  // odd
  2. else   // even
Mar 11 '09 #2
donbock
2,426 Expert 2GB
@AsHantoosH
By "multiple of 2", do you mean "even" (2, 4, 6, 8, 10, ...) or do you mean "power of two" (2, 4, 8, 16, 32, ...)?
Mar 11 '09 #3
i mean multiple of 2 (2,4,6)
Mar 11 '09 #4
Meetee
931 Expert Mod 512MB
In your even number logic you can extends the logic for the multiplicity of 2 as every even number except 0. So modify your logic accordingly.

Regards
Mar 12 '09 #5
scruggsy
147 100+
@zodilla58
Not to be nitpicky (or rather, to be very nitpicky :p) but zero is a multiple of all numbers but a factor of none. Negative even numbers are also multiples of 2. Whether either applies in this case depends on the problem statement I guess - OP doesn't specify.
Mar 12 '09 #6
[ incorrect spoonfeeding code deleted ]

Jos (moderator)
Mar 15 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online...
13
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if...
5
by: cai_rongxi | last post by:
Anyone has the solution to the question "Given an array a with value 1...N, find a repeted value" in C code? Thanks a lot
18
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When...
16
by: Java script Dude | last post by:
Creating a method of object (Object.prototype.classOf ...) is not the correct way because of a (as expected) flaw in IE where DOM Elements does not inherit from Object. As a result it is best to...
21
by: Imran | last post by:
I have a vector of integers, such as and I want to find out the number which occurs most frequently.what is the quick method. My array size is huge. what I am doing is 1. find out the...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
22
by: Steve Richter | last post by:
Does the .NET framework provide a class which will find the item in the collection with a key which is closest ( greater than or equal, less than or equal ) to the keys of the collection? ex:...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.