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.

Answers were Sorted based on User's Feedback



using repetition structure. Write a c program that will accept five numbers. The program should cou..

Answer / abikrishna

#include <iostream>
using namespace std;



int main ()
{
int a[6],i,ec=0,oc=0;
for(i=0;i<5;i++)
cin>>a[i];

for (i=0;i<5;i++)
{
if (a[i]%2==0)
ec++;
else
oc++;
}
cout<<"\t Even Count is : "<<ec;
cout<<"\t Odd Count is : "<<oc;

return 0;
}

Is This Answer Correct ?    22 Yes 9 No

using repetition structure. Write a c program that will accept five numbers. The program should cou..

Answer / 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

More C++ Code Interview Questions

Code for Method of Handling Factorials of Any Size?

0 Answers  


Hello, I am trying to write a program in c++ which accepts month and year from the user and prints the calender. So please tell me the algorithm and what is the calender logic.

0 Answers  


An array of size 5X5 is given to us. The elements from 1 to 25 are to be inserted in the array, such that starting from a particular position for an element i, the next element i+1can be inserted only at the mentioned positions (u,v), and if these all positions are occupied then it returns giving a count of how many positions have been occupied in the array: (u,v) = (x+/-3 , y) (u,v) = (x , y+/-3) (u,v) = (x+/-2 , y+/-2). Example: if the starting element is 1 with the given positions (1,2), then next element 2 can be placed at any one of the positions marked with *. _ _ _ _ _ 1 _ _ _ * _ _ _ _ _ _ _ * _ _ * _ _ _ _

0 Answers   Nagarro,


main(){int a=5,b 10,c=2, d;a=b c;d=++a=(--c)*2; printf("%d%d%d%d,a,b,c,d; return o;}

1 Answers  


What will be the output- for(i=1;i<=3;i++) { printf("%d",i); continue; i++; }

5 Answers   Impetus,






can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

0 Answers  


Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

0 Answers  


Subsets Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a list that is the input to the algorithm. (Since it is a set, you may assume all elements in the list are distinct.)

1 Answers   CSC, Qatar University,


what is the diffrence between ++x , x++ pleaaaaase ???

7 Answers  


hello friends, given an expression we have to remove the unwanted brackets in that expression. Eg : (a+b) ---> a+b (a+b)*(c)-----> (a+b)*c. Please mail me if you know the logic. My mail id is : saravana6m@gmail.com. Thank you in advance :-)

1 Answers   GrapeCity, Microsoft,


Write a program using one dimensional array that accept five values from the keyboard. Then it should also accept a number to search. This number is to be searched if it among the five input values. If it is found, display the message “Search number is found!” otherwise, display “Search is lost”. Example: Enter 5 numbers: 10 15 20 7 8 Enter number to search: 7 Search number is found!

2 Answers   College School Exams Tests,


A research student is given a singly-linked list. Each node of the list has a color, which is either “Black” or “White”. He must find if there are more black nodes than white nodes, or vice versa. His advisor gives him 5,000Rs to buy a computer to do the work. He goes to the computer store and finds a slightly defective computer which costs a mere 3,000Rs. This computer has the small problem of not being able to do arithmetic. This means that he cannot use a counter to count the nodes in the list to determine the majority color. The computer is otherwise fully functional. He has the evil idea that he could buy the defective computer and somehow use it to do his work, so that he can use the rest of the money on enjoyment. Show how he can accomplish this amazing task. Write code for an algorithm called ‘findMajorityColor’ which takes a singly-linked list, L, with n nodes and returns the majority color among nodes of L. This algorithm should have the same asymptotic running time as counting the nodes (O(n)). Note: No arithmetic is allowed.

2 Answers  


Categories