Thread: Divisible Program

  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, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM