Given:
- Total students = 40
- Total teachers = 5
Step 1: Calculate sweets per student
Each student got sweets equal to 15\% of total students
= 15\% of 40 = $\frac{15}{100} \times 40 = 6$ sweets per student
Step 2: Calculate sweets per teacher
Each teacher got sweets equal to 20\% of total students
= 20\% of 40 = $\frac{20}{100} \times 40 = 8$ sweets per teacher
Step 3: Calculate total sweets
Total sweets for students = $40 \times 6 = 240$
Total sweets for teachers = $5 \times 8 = 40$
Total sweets = 240 + 40 = 280
Hence, the total number of sweets is 280.