using repetition structure. Write a c program that will
accept five numbers. The program should count and output the
total count of even numbers and total count of add numbers.

Answer Posted / john

#include <iostream>
using namespace std;

int main(){
int array[5];
int i;
int evens = 0;
int odds = 0;

for(i = 0; i < 5; i ++){
cout << "Enter number: ";
cin >> array[i];
if(array[i] & 1)
odds++;
else evens++;
}

cout << "\nEvens: " << evens;
cout << "\nOdds: " << odds;
}

Is This Answer Correct ?    7 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Code for Method of Handling Factorials of Any Size?

2007


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

2407


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

2051


Write a simple encryption program using string function which apply the substitution method.

5539


1+1/2!+1/3!+...+1/n!

1945






What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

580


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

3959


write a program that reads a series of strings and prints only those strings begging with letter "b"

2674


write a program using virtual function to find the transposing of a square matrix?

2845


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2067


write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

4310


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

3274


how to write a program that opens a file and display in reverse order?

2568


How to swap two ASCII numbers?

2451


output for printf("printf");

1985