Fortran में **Functions** और **Subroutines** का उपयोग प्रोग्राम को छोटे, प्रबंधनीय हिस्सों में विभाजित करने के लिए किया जाता है। यह प्रोग्रामिंग को अधिक संगठित और कुशल बनाता है। Functions और Subroutines आपको कोड को पुन: उपयोग करने, जटिल गणनाओं को सरल बनाने, और प्रोग्राम के लॉजिक को स्पष्ट रूप से प्रस्तुत करने में मदद करते हैं। इस अध्याय में, हम Functions और Subroutines को डिक्लेयर करने, कॉल करने, और उनके उपयोग के तरीके सीखेंगे।
Functions क्या हैं?
Fortran में Functions छोटे प्रोग्रामिंग ब्लॉक्स होते हैं, जो किसी विशिष्ट कार्य या गणना को निष्पादित करते हैं और एक मान (value) लौटाते हैं। Functions का उपयोग तब किया जाता है जब आपको एक ही कार्य को कई बार उपयोग करना हो। Functions प्रोग्रामिंग को अधिक संगठित, कुशल और पुन: प्रयोज्य बनाते हैं, जिससे जटिल गणनाएँ और प्रक्रियाएँ आसान हो जाती हैं।
Functions का परिचय:
Functions को प्रोग्राम के भीतर अलग-अलग स्थानों पर बुलाया जा सकता है। जब कोई Function बुलाया जाता है, तो यह विशिष्ट इनपुट मानों के आधार पर एक आउटपुट प्रदान करता है। Fortran में Functions का उपयोग मुख्य रूप से गणितीय और तार्किक गणनाओं को सरल और दोहराने योग्य बनाने के लिए किया जाता है।
Functions की विशेषताएँ:
- इनपुट पैरामीटर्स: Functions इनपुट के रूप में एक या अधिक मान लेते हैं।
- आउटपुट: Function एक परिणाम (रिटर्न वैल्यू) वापस करता है।
- पुन: प्रयोज्य कोड: Functions का उपयोग करके कोड को कई बार बिना दोहराए पुन: उपयोग किया जा सकता है।
1. एक साधारण Function का उदाहरण:
program function_example
real :: x, result
! Function को कॉल करना
x = 5.0
result = square(x)
print *, "5 का वर्ग:", result
end program function_example
! Function डिफ़िनिशन
real function square(a)
real :: a
square = a * a
end function square
स्पष्टीकरण:
squareनाम का एक Function परिभाषित किया गया है, जो दिए गए इनपुटaका वर्ग (square) लौटाता है।squareको प्रोग्राम के भीतरx = 5.0के साथ बुलाया गया है, और परिणाम (25.0) प्रिंट किया जाता है।
2. In-line Functions:
In-line Functions का मतलब है कि Function के शरीर को उसी लाइन में लिखा जाता है जहाँ इसका उपयोग किया जाता है। Fortran में इनलाइन Functions का उपयोग सरल गणनाओं के लिए किया जाता है, जहाँ Function को अलग से परिभाषित करने की बजाय उसी स्थान पर गणना की जाती है। यह छोटे और त्वरित कार्यों के लिए उपयोगी होता है, जहाँ Function का उपयोग कई बार किया जाता है।
In-line Function का उदाहरण:
program inline_function_example
real :: x, result
! In-line Function का उपयोग करते हुए
x = 4.0
result = (x ** 2 + 2.0 * x + 1.0) ! गणितीय Function इनलाइन उपयोग किया गया है
print *, "In-line Function का परिणाम:", result
end program inline_function_example
स्पष्टीकरण:
- इस उदाहरण में, गणितीय Function
(x ** 2 + 2.0 * x + 1.0)को सीधे उसी स्थान पर लिखा गया है जहाँ गणना की जा रही है। इसे एक बार उपयोग करने के लिए अलग Function लिखने की बजाय इनलाइन लिखा गया है। - यह त्वरित और छोटे कार्यों के लिए उपयोगी होता है, जहाँ Function को बार-बार बुलाने की आवश्यकता नहीं होती है।
3. Functions का उपयोग:
Functions का उपयोग प्रोग्रामिंग में कई प्रकार से किया जाता है:
- गणितीय ऑपरेशन्स: Functions गणितीय और वैज्ञानिक गणनाओं को सरल और पुन: प्रयोज्य बनाते हैं।
- तार्किक गणना: Functions का उपयोग तार्किक निर्णयों को नियंत्रित करने के लिए किया जा सकता है।
- पुन: प्रयोज्य कोड: एक बार Function लिखने के बाद, इसे प्रोग्राम में कई बार बुलाया जा सकता है, जिससे कोड को बार-बार लिखने की आवश्यकता नहीं होती है।
Functions के लाभ:
- Modularity: Functions कोड को छोटे, स्वतंत्र ब्लॉक्स में विभाजित करते हैं, जिससे प्रोग्राम को समझना और प्रबंधित करना आसान होता है।
- पुन: उपयोग (Reusability): एक Function को कई बार और कई स्थानों पर उपयोग किया जा सकता है, जिससे कोड की पुनरावृत्ति कम होती है।
- संगठित प्रोग्रामिंग: Functions प्रोग्राम को अधिक संगठित बनाते हैं, क्योंकि आप जटिल कार्यों को छोटे और प्रबंधनीय भागों में विभाजित कर सकते हैं।
Subroutines
Fortran में Subroutines का उपयोग जटिल कार्यों या गणनाओं को छोटे, पुन: उपयोग करने योग्य ब्लॉक्स में विभाजित करने के लिए किया जाता है। Subroutines और Functions दोनों ही प्रोग्राम के हिस्सों को अलग-अलग कार्यों में विभाजित करते हैं, लेकिन Subroutines का उपयोग तब होता है जब हमें कई मान (values) को बदलना या प्रभावित करना होता है और कोई परिणाम वापस नहीं करना होता है। Subroutines का उपयोग करके आप कोड को अधिक संगठित और कुशल बना सकते हैं।
1. Subroutines का प्रयोग और Syntax:
Subroutines उन कार्यों के लिए उपयोगी होती हैं जहाँ हमें कई मानों को पास करना और बदलना हो। Subroutines को call स्टेटमेंट के साथ बुलाया जाता है और Subroutines के अंदर वेरिएबल्स को modify किया जा सकता है।
Syntax:
subroutine subroutine_name(arguments)
! Subroutine के कोड
end subroutine subroutine_name
- subroutine_name: Subroutine का नाम।
- arguments: वेरिएबल्स जो Subroutine के अंदर पास किए जाते हैं।
उदाहरण:
program subroutine_example
real :: x, y
x = 5.0
y = 10.0
! Subroutine को कॉल करना
call swap(x, y)
print *, "x:", x, "y:", y
end program subroutine_example
! Subroutine डिफ़िनिशन
subroutine swap(a, b)
real :: a, b
real :: temp
! मानों की अदला-बदली
temp = a
a = b
b = temp
end subroutine swap
स्पष्टीकरण:
swapनामक Subroutine का उपयोगxऔरyके मानों को बदलने के लिए किया गया है।- Subroutine को
callकरके बुलाया गया, और Subroutine के अंदरxऔरyके मानों की अदला-बदली की गई। - Subroutines में आप बिना किसी परिणाम वापस किए भी कई मानों पर ऑपरेशन्स कर सकते हैं।
2. Modules और Subroutines का परिचय:
Modules का उपयोग Fortran में कोड को बेहतर ढंग से संगठित करने और पुन: उपयोग करने के लिए किया जाता है। Modules का उपयोग करके आप कई Subroutines और Functions को एक जगह पर संग्रहित कर सकते हैं, जिससे उन्हें अन्य प्रोग्राम या मॉड्यूल्स में आसानी से उपयोग किया जा सके।
Modules और Subroutines का संयोजन आपके प्रोग्राम को और अधिक शक्तिशाली और मॉड्यूलर बनाता है। Subroutines को Modules के अंदर डिफ़ाइन किया जा सकता है, और फिर उस मॉड्यूल को अन्य प्रोग्राम्स में इम्पोर्ट किया जा सकता है।
Syntax:
module my_module
contains
subroutine my_subroutine(arguments)
! Subroutine का कोड
end subroutine my_subroutine
end module my_module
- module my_module: यह मॉड्यूल
my_moduleनाम से परिभाषित किया गया है। - contains: यह कीवर्ड दर्शाता है कि मॉड्यूल के अंदर Subroutines या Functions हैं।
- subroutine my_subroutine: यह मॉड्यूल के अंदर डिफ़ाइन की गई Subroutine है।
उदाहरण:
program module_example
use my_module
real :: x, y
x = 3.0
y = 7.0
! Subroutine को कॉल करना
call add_values(x, y)
end program module_example
module my_module
contains
subroutine add_values(a, b)
real :: a, b
real :: result
result = a + b
print *, "योग:", result
end subroutine add_values
end module my_module
स्पष्टीकरण:
- यहाँ
my_moduleनाम का एक मॉड्यूल बनाया गया है, जिसमेंadd_valuesनाम की Subroutine है। - प्रोग्राम में
useस्टेटमेंट के द्वारा मॉड्यूल को इम्पोर्ट किया गया औरcall add_values(x, y)के द्वारा Subroutine को बुलाया गया। - इस Subroutine में दो मानों
aऔरbका योग किया गया और परिणाम प्रिंट किया गया।
Modules के लाभ:
- कोड का पुन: उपयोग (Reusability): Modules के अंदर Functions और Subroutines को एक बार लिखने के बाद, उन्हें कई प्रोग्राम्स में उपयोग किया जा सकता है।
- बेहतर संगठन: Modules प्रोग्राम को अधिक संगठित बनाते हैं, क्योंकि कोड के विभिन्न हिस्सों को एक स्थान पर संग्रहित किया जाता है।
- अधिक स्पष्टता: Modules का उपयोग करने से प्रोग्राम अधिक स्पष्ट और सुव्यवस्थित दिखता है, क्योंकि Subroutines और Functions को एक ही स्थान पर रखा जाता है।

tizanidine hydrochloride: methocarbamol robaxin – tizanidine medication
http://spasmreliefprotocols.com/# antispasmodic medication
https://spasmreliefprotocols.com/# over the counter muscle relaxers that work
buy methocarbamol without prescription: buy methocarbamol – tizanidine hcl
BajaMed Direct: best mexican online pharmacy – BajaMed Direct
http://bajameddirect.com/# BajaMed Direct
mexican pharmacies near me: mexico meds – BajaMed Direct
https://indogenericexport.com/# muscle relaxer medication
US Meds Outlet: economy pharmacy – US Meds Outlet
BajaMed Direct: BajaMed Direct – BajaMed Direct
https://indogenericexport.com/# muscle relaxer tizanidine
online shopping pharmacy india: Indo-Generic Export – п»їlegitimate online pharmacies india
https://indogenericexport.shop/# methocarbamol medication
US Meds Outlet: US Meds Outlet – pharmacy rx world canada
best online pharmacy india: buy medicines online in india – top 10 pharmacies in india
https://usmedsoutlet.shop/# legitimate canadian pharmacy online
mexico pharmacy price list: mexicanrxpharm – BajaMed Direct
BajaMed Direct: BajaMed Direct – mexican pharmacy las vegas
canadapharmacyonline legit: bitcoin pharmacy online – US Meds Outlet
BajaMed Direct: BajaMed Direct – online pharmacies
best online pet pharmacy: canadian valley pharmacy – all med pharmacy
medication in mexico: online mexican pharmacies – BajaMed Direct
http://indogenericexport.com/# indian pharmacy online
india pharmacy: Indo-Generic Export – online shopping pharmacy india
https://indogenericexport.shop/# reputable indian pharmacies
US Meds Outlet: online pharmacy meds – US Meds Outlet
indian pharmacy: top 10 online pharmacy in india – buy prescription drugs from india
http://usmedsoutlet.com/# US Meds Outlet
onlinecanadianpharmacy: online pharmacy australia paypal – canadadrugpharmacy com
the canadian pharmacy: US Meds Outlet – us pharmacy
https://indogenericexport.shop/# india pharmacy mail order
pharmacy in mexico city: BajaMed Direct – BajaMed Direct
https://indogenericexport.com/# best india pharmacy
pharmacy home delivery: US Meds Outlet – US Meds Outlet
indianpharmacy com: Indo-Generic Export – indianpharmacy com
http://usmedsoutlet.com/# US Meds Outlet
top 10 online pharmacy in india: best online pharmacy india – Online medicine order
BajaMed Direct: los algodones pharmacy online – BajaMed Direct
http://usmedsoutlet.com/# US Meds Outlet
BajaMed Direct: farmacias mexicanas – pharmacy in mexico city
http://usmedsoutlet.com/# US Meds Outlet
pharmacy in mexico city: BajaMed Direct – BajaMed Direct
zoloft buy: generic for zoloft – zoloft buy
http://neuroreliefusa.com/# neurontin 600mg
http://ivertherapeutics.com/# stromectol tablets
zoloft tablet: zoloft without rx – zoloft tablet
http://smartgenrxusa.com/# canadianpharmacymeds com
ivermectin pills human: Iver Therapeutics – ivermectin nz
https://ivertherapeutics.com/# Iver Therapeutics
Smart GenRx USA: pharmacy coupons – Smart GenRx USA
http://ivertherapeutics.com/# ivermectin 3mg pill
Smart GenRx USA: Smart GenRx USA – peoples pharmacy
https://smartgenrxusa.shop/# cheap canadian pharmacy
sertraline zoloft: order zoloft – zoloft generic
Neuro Relief USA: where can i buy neurontin online – neurontin 214
http://ivertherapeutics.com/# Iver Therapeutics
Iver Therapeutics: Iver Therapeutics – Iver Therapeutics
https://sertralineusa.com/# zoloft without dr prescription