Hello guys i need help,
I need to write a program that count how many nubers can be divide in a interval from k to n, exemple in a interval from 1 - 10 theare "3" numbers that can be divide with 3, here is my program:
1.

#include <iostream.h>
void main()
{
int k,x,n;
cout <<"k = ";
cin >> k;
cout << "n = ";
cin >> n;
x = k + 1;
for (x>k;x<n;x++)
{
 if (k%3==0; n%3==0)
 cout << ((n-k)/3)-1;
 else
 if (k%3!==0; n%3==0)
 cout <<((n-k)/3);
 else
 if (k%3!==0; n%3!==0)
 cout <<((n-k)/3);
 }}
or 
2.
#include <iostream.h> // But this program just write ex. from 1 - 10 
void main()                      ( 3, 6, 9), but I need that he write there   
{                                      3 numbers.
int k,x,n,t;
cout <<"k = ";
cin >> k;
cout << "n = ";
cin >> n;

for (x=k;x<=n;x++)
{
if(x%3==0)
cout << x;
else
cout <<" ";
}}

Can anyone help!!

Edited 7 Years Ago by Nick Evan: Added code-tags (which improve nothing...)

>>I need to write a program that count how many nubers can be divide in a interval from k to n, exemple in a interval from 1 - 10 theare "3" numbers that can be divide with 3, here is my program:

Explain a bit more.

Yes explain some more, you havent explained enough for people to help you! Also put code into [code] CODE HERE [/code] so people can view it easier and more chance of help!

Edited 7 Years Ago by Nick Evan: noparse-tags added

My program need to count how many numbers in a interval from k to n can be divide with 3 ex. in a interval from 1 - 16 my program need to write "there are 5 numbers that can be divide with 3" and not (3, 6, 9 12, 15) or in a interval from 1 - 20 "there are 6 numbers that can be divide with 3" and dont to write the numbers that can be divide with 3
(3, 6, 9, 12, 15, 18).

I finish the program, and it works thx.
P.S. here is the program when anyone need it

#include <iostream.h>
void main()
{
int k,x,n,t,;
t = 0;
cout <<"k = ";
cin >> k;
cout << "n = ";
cin >> n;

for (x=k;x<=n;x++)
{
if(x%3==0)
t += 1;
}

cout << t;
}

Edited 7 Years Ago by Dex02: n/a

This article has been dead for over six months. Start a new discussion instead.