R language wap to print the number from 1 to 100 and check that they are divisible by 3 and divisible by 5 and divisible by both | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

R language wap to print the number from 1 to 100 and check that they are divisible by 3 and divisible by 5 and divisible by both

print("generating a numbers by Khushi from 1 to 100 range ") #start=1 #stop=100 #stepsize=1 matlab humare 1 se in increment hoga for i in range (1,100,1) if(i%3==0) { print (the number is divisible by 3) } else if(i %5==0) { print ("the number is divisible by 5") } else { if (i%3&&i%5==0) { print("the number is divisible by both 3 and 5") } } Please check the code and solution provide it

11th Sep 2022, 7:09 AM
Abhishek
Abhishek - avatar
5 Answers
+ 1
People are more likely to test your code if you put them on sololearn playground instead of pasting it i to the description. The R range() does not work like the Python range() First check if the number is divisible by 3 && 5, then if it is divisible by 3 or 5.
11th Sep 2022, 8:32 AM
Lisa
Lisa - avatar
+ 1
Yes, it is not working. READ MY PREVIOUS COMMENT.
11th Sep 2022, 10:56 AM
Lisa
Lisa - avatar
0
for(x in 1:100){ + if(x%%10==0){ + print(x) + } + }
11th Sep 2022, 10:41 AM
Abhishek
Abhishek - avatar
- 2
print("generating a numbers by Khushi from 1 to 100 range ") #start=1 #stop=100 #stepsize=1 matlab humare 1 se in increment hoga for( i in 1:100) if(i%%3==0) { print (i,the number is divisible by 3) } else if(i %%5==0) { print (i,"the number is divisible by 5") } else { if (i%%3 & i%%5==0) { print( i ,"the number is divisible by both 3 and 5") } }
11th Sep 2022, 10:39 AM
Abhishek
Abhishek - avatar
- 2
My code is not working
11th Sep 2022, 10:39 AM
Abhishek
Abhishek - avatar