Lesson 14 of 23

FunctionsFunctions

10 min 25 XP

Function ஒரு பெயர் கொண்ட code தொகுப்பு. return type, பெயர், parameters. main()-க்கு கீழே function எழுதினால் மேலே ஒரு prototype (அறிவிப்பு) வேண்டும்.

A function is a named block of code with a return type, a name and parameters. If you define it below main(), declare a prototype above main().

Example: edit me and press Run

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

C-ல் arguments மதிப்பாக (call by value) அனுப்பப்படும்: function உள்ளே parameter-ஐ மாற்றினால் main-ல் உள்ள variable மாறாது. மாற்ற வேண்டுமெனில் pointers தேவை (அடுத்த module).

C passes arguments by value: changing a parameter inside a function doesn't change the caller's variable. To change it you need pointers (next module).

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

int gcd(int a, int b) என்ற function எழுதுங்கள் (Euclid முறை). main()-ல் a, b படித்து GCD மற்றும் LCM print செய்யுங்கள். Input: 12 18 Output: GCD: 6 LCM: 36

Write a function int gcd(int a, int b) using Euclid's method. In main(), read a and b and print the GCD and LCM. Input: 12 18 Output: GCD: 6 LCM: 36

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