Lesson 14 of 23

Functions

10 min 25 XP

Function कोड का नाम वाला block है जिसमें return type, नाम और parameters होते हैं। अगर इसे main() के नीचे define करें, तो main() के ऊपर एक prototype declare करें।

Example: edit me and press Run

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

C arguments को value से भेजता है: function के अंदर parameter बदलने से caller का variable नहीं बदलता। उसे बदलने के लिए pointers चाहिए (अगला 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

Euclid की विधि से function int gcd(int a, int b) लिखें। main() में a और b पढ़ें और GCD व LCM print करें। Input: 12 18 Output: GCD: 6 LCM: 36

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