+ 6

Programme for composite number??

If i enter any no. All composite no. should be print in between 1 and given no.

29th Oct 2017, 6:46 AM
Saransh Maurya
Saransh Maurya - avatar
4 odpowiedzi
+ 6
Sure I will do this.
29th Oct 2017, 7:59 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Cool i got it thanks
29th Oct 2017, 9:03 AM
Saransh Maurya
Saransh Maurya - avatar
+ 3
#include <iostream> using namespace std; int main() { int number; cin >> number; for (int i = 3; i <= number ; i++){ for (int j = 2; j < i; j++){ if (i%j == 0){ cout << i << " "; j=i; } } } return 0; } edited it a bit because i had some not needed code there
29th Oct 2017, 8:11 AM
imouse
imouse - avatar
+ 2
/* from @pegasus code, i edited the second for to make the program faster, because we just need to check the number can divide from 2 to square root the number #include <iostream> #include <math.h> using namespace std; int main() { int number; cin >> number; for (int i = 3; i <= number ; i++){ for (int j = 2; j <= sqrt (i); j++){ if (i%j == 0){ cout << i << " "; j=i; } } } return 0; }
29th Oct 2017, 10:31 AM
ramabena
ramabena - avatar