Lesson 7 of 23

for LoopThe for Loop

8 min 25 XP

for (தொடக்கம்; condition; மாற்றம்). Condition true ஆக இருக்கும் வரை loop இயங்கும். கூட்டுத்தொகை, பெருக்கல் வாய்ப்பாடு, factorial போன்றவற்றுக்கு இதுவே அடிப்படை.

for (start; condition; step) runs while the condition is true. It is the building block for sums, multiplication tables and factorials.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

பெரிய எண்களுக்கு long long பயன்படுத்துங்கள்; அதை print செய்ய %lld. int சுமார் 2 பில்லியன் வரை மட்டுமே.

Use long long for big numbers and print it with %lld. An int only goes up to about 2 billion.

Challenge

+25 XP

n-ஐப் படித்து 1 முதல் n வரை உள்ள இரட்டை (even) எண்களின் கூட்டுத்தொகையை print செய்யுங்கள். Input: 10 → Output: 30

Read n and print the sum of the even numbers from 1 to n. Input: 10 → Output: 30

Output Loading C (first time takes a few seconds)
Press Run to see the result here.