Lesson 7 of 24

Functions, Default Arguments, OverloadingFunctions, Default Arguments and Overloading

9 min 25 XP

C++-ல் ஒரே பெயரில் பல functions எழுதலாம் (overloading), parameters வேறுபட்டால் போதும். Default arguments மூலம் சில parameters-ஐ விருப்பத்திற்குரியதாக்கலாம்.

C++ lets several functions share a name as long as their parameters differ (overloading). Default arguments make trailing parameters optional.

Example: edit me and press Run

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

Challenge

+25 XP

bool isPrime(int n) என்ற function எழுதுங்கள். main()-ல் n படித்து 2 முதல் n வரை உள்ள prime எண்களை space விட்டு print செய்யுங்கள். Input: 20 → Output: 2 3 5 7 11 13 17 19

Write bool isPrime(int n). In main(), read n and print every prime from 2 to n separated by spaces. Input: 20 → Output: 2 3 5 7 11 13 17 19

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