Display the odd number up-to 30 by R4R Team

What is odd number ?

odd nuumber are those number which on divide by 2 leaves a remainder of 1 like 1,3,5,7,.............

program to display the odd number upto 30-

#first way
print("By for loop, odd number upto 30")
for i in range(31):
if i%2==1:
print(i,end=" ")

#second way
print("nBy while loop,even number upto 20")
i=1
while(i<30):
print(i,end=" ")
i=i+2


output -

By for loop, odd number upto 30
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
By while loop,even number upto 20
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29


In this program, in first part we use for loop in which we check number that it is odd number or not but in second part we start with 1 value and increase the value by 2 and print upto 30.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!