0
#include <iostream>
using namespace std;

int main() {
	int numbers;
	numbers = 2;
while (numbers <= 1000);
{
	if (numbers % 2 ==0){cout<< numbers;};
	
	if	(numbers % 3 ==0){cout<< numbers;};
	 
		if	(numbers % 4 ==0){cout<< numbers;};
 
	if	(numbers % 5 ==0){cout<< numbers;};

		if	(numbers % 6 ==0){cout<< numbers;};

	if	(numbers % 8 ==0){cout<< numbers;};
	 
		if	(numbers % 9 ==0){cout<< numbers;};
 
	if	(numbers % 7 ==0){cout<< numbers;};
	
	if		(numbers % 11 ==0){cout<< numbers;};
++numbers;
}
cout<<numbers;
	return 0 ;
}

as you can see when i debug it, no digit will appear...how can i handle this one..need some help folks...

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by chococrack
0

remove the semicolon after (numbers <= 1000)
as well as all the semicolons after the closing braces in your if statements

I believe you're attempting this:

#include <iostream>
using namespace std;
 
int main() {
	int numbers;
	numbers = 2;

	while (numbers <= 1000) {
		if (numbers % 2 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 3 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 4 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 5 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 6 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 8 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 9 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 7 ==0){cout<< numbers <<endl;}
	 
		if (numbers % 11 ==0){cout<< numbers <<endl;}
		++numbers;
	}
	cout<<numbers;
	return 0 ;
}
0

sir...but how can i get this sorter..by using int divi for its divisible..to get even the highest possible prime number extracted?

0

You're on the right track, but you're not getting the prime number part correct.

Try re-writing the inside of your while loop

and remove the cout << numbers after the loop, as you wouldn't want to print anything there


in other words

#include <iostream>
using namespace std;
 
int main() {
	int number;
	number = 2;

	while (number <= 1000) {

                ...
		IF number IS PRIME THEN
                   PRINT number
                ...

		++number;
	}

	return 0 ;
}

Edited by chococrack: n/a

0
#include <iostream>
using namespace std;

int main() {
    int numbers;
    int divi;
    numbers = 2;
    divi = 0 ;

while (numbers <= 1000)
{
    if (numbers % divi ==0){numbers++;};

cout<< numbers<< "\t";

divi++;

}

    return 0 ;
}

this is my update on this

Edited by Nick Evan: Fixed formatting

0
[B]isPrime = true

num = 2

while num <= 1000
     for i in( 2 to num/2 )
	    if num % i = zero
                isPrime = FALSE
	    endif
     endfor
	
     if isPrime = TRUE
         PRINT num
     endif
	
     increment num
     isPrime = TRUE
endwhile[/B]

Edited by chococrack: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.