answersLogoWhite

0


Best Answer

#include<iostream>

using namespace std;

void main() {

int odd,even,number;

odd=0;

even=0;

for(int x=1;x<=10;x=x+1){

cout<<"enter a number\n";

cin>>number;

if(number%2==0){

even++;

}

else {

odd++;

}

}

cout<<"even number has:"<<even;

cout<<"odd number has:"<<odd;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

for persons who are wondering how to do this its really simple.

/* CLAUDE ANTHONY BURRELL*/

/* C CODE FOR EVENSUM*/

#include<stdio.h>

#include<stdlib.h>

int valChar(int*, char);

int main()

{

int values[11];

char alpha;

int evenSum;

int i;

printf("\t C PROGRAM FOR ALL EVEN NUMBERS AND FIND THE SUM\n\n\n\n");

system("color e");

for(i = 0; i < 10; i++)

{

printf("PLEASE ENTER %d VALUE\n",i); /* READING 10 DIFFERENT NUMBERS IN VALUES*/

scanf("%d",&values[i]);

}//end for

fflush(stdin);

printf("ENTER A CHARACTER\n\n");

scanf("%c",&alpha);

evenSum = valChar(values,alpha);/* RETURNS THE SUM OF EVEN NUMBERS IF THE CHARACTER IS 'A' OR 'a'*/

printf("THE SUM OF THE NUMBER IS = %d ",evenSum);

system("pause");

}//end main

int valChar(int * values, char alpha)

{

int i;

int evenSum = 0;

for(i = 0; i< 10; i++)

{

if (alpha 'A')

{

if (values[i]%2==0)

{

//even = values[i] % 2 = 0;

evenSum = evenSum + values[i];

}//end if

}//end if

else

{

evenSum = evenSum + values[i];

}//end else

}//end for

return evenSum;

}//end valChar

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

bool is_odd (unsigned n) {

return n & 1;

}

This function simply tests to see if the low-order bit is set using the bitwise-AND binary operator (&). If it is, the number must be odd because the low order bit represents 2^0 which is 1. All other bits represent increasing powers of 2 (2, 4, 8, 16, etc) so the low-order bit alone determines if a number is odd (is set) or even (is not set).

Note that the argument must be unsigned. This is because negative values are implementation-defined and may use ones-complement or twos-complement notation, depending on the implementation. The function will only work with signed integers using twos-complement notation. Twos-complement is more common than ones-complement, however portability is not guaranteed.

For a portable solution that caters for both ones-complement and two-complement signed integers, use the modus operator instead:

bool is_odd (signed n) {

return n % 2;

}

The modus operator returns the remainder after division. When we divide any signed integer by 2, the remainder can only be 0 (is even) or 1 (is odd).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c to find even and odd nos?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Using while loop write a program which calculates the product of digits from 1 to 5 and also show these nos vertically?

Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.


Could u draw me a flowchart for this C program question 1.sum of nos. from 1 to n Check the no. in odd or even?

1. Read in 'n'2. Output n*(n+1)/2> Check the no. in odd or even?Both possible, has no significance.


Find the sum of 1 plus 2 plus 3 plus . plus n nos using c program?

if (n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n;


Write a c program to sort three integer numbers using nested if statement?

// HI THIS IS MAYANK PATEL /*C Program to find Maximum of 3 nos. using Nested if*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int a,b,c; // clrscr(); printf("Enter three number\n\n"); scanf("d%d",&amp;a,&amp;b,&amp;c); if(a&gt;b) { if(a&gt;c) { printf("\n a is maximum"); } else { printf("\n c is maximum"); } } else { if(b&gt;c) { printf("\n b is maximum"); } else { printf("\n c is maximum"); } } getch(); }


A c program to interchange odd and even components of an array?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int a[10],i,evc=0,odc =0;// sum=0; clrscr(); printf("enter 10 no.s in the array\n"); for(i=0;i&lt;=9;i++) { scanf("%d",&amp;a[i]); } for(i=0;i&lt;=9;i++) { if(a[i]%2==0) { evc=evc+1; } else { odc=odc+1; } } printf("Even nos %d\n",evc); printf("odd nos %d\n",odc); getch(); } 0"). This is a perfectly valid and correct approach, but in many implementations, a simple test for the least significant bit ("a[i] &amp; 1") can be more efficient. This also allows to replace logic with arithmetic, which generally is more efficient (i.e. "odc += a[i] &amp; 1")

Related questions

How do you print nos from 10-0 then only even nos are printed in a program flowchart?

10


Write a c program to print the 100 to 1 nos?

Write a c program to print the 100 to 1 nos


Using while loop write a program which calculates the product of digits from 1 to 5 and also show these nos vertically?

Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.


How do you write see you there in Spanish?

nos vemos


How do you write 10 million in nos?

10,000,000


C program to accept a sequence of number terminated by zero and sum all odd nos and even nos?

#include &lt;stdio.h&gt; main() { int n, odd=0, even=0; while (scanf("%d",&amp;n)&amp;&amp;(n!=0)) (n%2)?++odd:++even; printf("odd: %d even: %d\n",odd,even); }


What does escreva nos mean in Portuguese?

Write (to) us


Write a programme to find the sum and product of three numbers?

//sum and product of 3 nos #include #include void main() { int a,b,c; printf("enter the 3 nos"); scanf("%d%d%d",&amp;a,&amp;b,&amp;c); printf("sum of 3 nos",a+b+c); printf("product of 3 nos",a*b*c); getch(); }


What will you get if you add s odd numbers and 2 even nos?

even


The product of two consecutive odd integers is 2 less than six times their sum can you find the two integers?

there cannot be any nos like that.. product of 2 odd nos is odd.. sum of two even nos is even.. that multiplied by six is even too.. subtracting 2 from that also gives an even no.. let x and y be the odd integers. according to the given question xy=6(x+y)-2..here we r actually equatin an odd no and an even no.. which is wrong.. so there cant be any two consecutive odd nos that fit in the question


What are even nos between 100 to 300 that is the sum of two prime nos?

Each one of them can be expressed as a sum of two primes.


Are all the factors of 100 even?

No most are odd nos.