+ 5
Getting the Output Multiple times..
In this program , the String [ Its Prime ] is shown 111 times . How can i get the output only once if every condition Here is true. https://code.sololearn.com/cCC39TcgxCyi/?ref=app
6 Respostas
+ 7
for i in range(2,a):
if a%i==0:
print("Its composite")
break
else:
print('Prime')
+ 5
Thanks Uzair Saeed for your help....
+ 3
you could write it inside a function and make the function return False if the first condition is True.
The second condition should be outside of the loop.
def primes(num):
for i in range(...):
if num%i ==0:
return False
print("prime")
+ 3
Mert Yazıcı ,davy hermans Davy thanks a lot for your help... đđđđđ
+ 1
int composite;
for (int number=2;number<=113;number++){
composite=0;
for (int reps=2;reps<=sqrt(number);reps++){
if (number%reps==0){
composite++;
break;
}}
if (composite==0){
cout<<"Its prime"<<endl;
}}
+ 1
Sorry, I can't code in python therefore I did it in c++