Divisible Program

This is a discussion on Divisible Program within the C++ Programming forums, part of the General Programming Boards category; For HW I'm suppose to : Write a program that finds out how many numbers below 10,000 are divisible by ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Divisible Program

    For HW I'm suppose to : Write a program that finds out how many numbers below 10,000 are divisible by both 3 and 26.

    This is what I have so far

    #include <iostream>
    using namespace std;
    int main ()
    {
    int z, counter;
    counter=0;

    for (int n =10000; n>=0; n+=78) {
    z = n % 78; //numbers divisible by 78 between10,000 are also divisible by both 3 and 26.

    if (z==0) {
    counter++; //counts the amount of numbers divisible by both

    }
    cout << counter << endl;


    system ("pause");
    }
    }

    This is what I get 0. I do not get what I did wrong. For the "for" I made it to start at 10,000 and keep subtracting 78 until it equals 0. Help please !!

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    I have no changed it to:

    #include <iostream>
    using namespace std;
    int main ()
    {
    int x,y,counter;
    counter=0;

    for (int n =10000; n>=0; n--) {
    x = n % 3;
    y = n % 2;

    if ((x==0) && (y==0)) {
    counter++;

    }
    cout << counter << endl;


    system ("pause");
    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C program displaying all numbers divisible by 6
    By DaniiChris in forum C Programming
    Replies: 25
    Last Post: 07-06-2008, 12:25 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21