#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
6 9074 @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: - if (a & 1) // odd
-
else // even
@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, ...)?
i mean multiple of 2 (2,4,6)
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
@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.
[ incorrect spoonfeeding code deleted ]
Jos (moderator)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |