Write a program that reads ten numbers (in an array), and counts the number of elements in the array that are divisible by 3.
What would this look like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[0];
int cnt = 0;
for (i = 0; i %26lt; 10; ++i)
{
if (ary[i] % 3 == 0)
++cnt;
}
cout %26lt;%26lt; cnt %26lt;%26lt; endl;
return 0;
}
Reply:all numbers are divisible by 3. No need to load them into an array.
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
Actually - I've seen someone earlier posting a nearly complete program to do the same thing but having problems withit.
chrysanthemum
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment