+ 6
Programme for composite number??
If i enter any no. All composite no. should be print in between 1 and given no.
4 Answers
+ 6
Sure I will do this.
+ 4
Cool i got it thanks
+ 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
+ 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;
}