Definition
This program is used to print all numbers from 1 to n that are divisible by both 3 and 5. A number is considered a multiple of 3 and 5 if it is exactly divisible by both numbers without any remainder.
Algorithm
Step 1: Start
Step 2: Input n
Step 3: Initialize i = 1
Step 4: Check whether i <= n
Step 5: If i is divisible by both 3 and 5, print i
Step 6: Increment i by 1
Step 7: Repeat Steps 4 to 6 until i > n
Step 8: Stop.
Flowchart:
┌───────┐
│ Start │
└───┬───┘
│
▼
┌──────────┐
│ Input n │
└────┬─────┘
│
▼
┌──────────┐
│ i = 1 │
└────┬─────┘
│
▼
┌────────┐
│ i <= n │
└──┬───┬─┘
Yes No
│ │
▼ ▼
┌────────────────┐
│ i%3==0 and │
│ i%5==0 ? │
└──┬─────────┬───┘
Yes No
│ │
▼ │
┌────────┐ │
│ Print i│ │
└────┬───┘ │
│ │
▼ │
┌────────┐ │
│ i=i+1 │◄────┘
└────┬───┘
│
└──────► Back to i <= n
No
│
▼
┌──────┐
│ Stop │
└──────┘
code:
n = int(input("Enter n: "))
i = 1
while i <= n:
if i % 3 == 0 and i % 5 == 0:
print(i)
i = i + 1
Input:
Enter n: 30
Output:
15
30
Top comments (0)