"फ़ोरट्रान": अवतरणों में अंतर

No edit summary
No edit summary
पंक्ति 2:
 
इसके कई कंपाइलर लिखे गए हैं, जैसे आईबीएम (मूल), एचपी, [[जीएनयू]] तथा अन्य कई। इसकी एक पंक्ति में 72 से अधिक वर्ण नहीं लिखे जा सकते हैं। पंक्ति के अंत में अर्धविराम नहीं लगता है। इस संदर्भ में इसकी तुलना C/C++ जैसी भाषाओं से की जा सकती है जिसमें अनुदेश खत्म होने के बाद एक अर्धविराम लगाना आवश्यक होता है।
 
==फोर्ट्रान कोड के उदाहरण==
निम्नलिखित प्रोग्राम, इन्टरैक्टिव रूप से इन्टर किये गये डेटा का [[औसत]] (average) निकालता है। इस प्रोग्राम में Fortran 90 के दो विशेष गुणों- डायनेमिक मेमोरी अल्लोकेशन तथा अर्रे-आधारित-संक्रियाएँ को दर्शाता है। ध्यान दीजिये कि इसमें <code>DO</code> लूप तथा <code>IF</code>/<code>THEN</code> का उपयोग करके अर्रे (array) को किस प्रकार परिवर्तित किया गया है।
 
<syntaxhighlight lang="fortran">
program average
 
! Read in some numbers and take the average
! As written, if there are no data points, an average of zero is returned
! While this may not be desired behavior, it keeps this example simple
 
implicit none
 
real, dimension(:), allocatable :: points
integer :: number_of_points
real :: average_points=0., positive_average=0., negative_average=0.
 
write (*,*) "Input number of points to average:"
read (*,*) number_of_points
 
allocate (points(number_of_points))
 
write (*,*) "Enter the points to average:"
read (*,*) points
 
! Take the average by summing points and dividing by number_of_points
if (number_of_points > 0) average_points = sum(points) / number_of_points
 
! Now form average over positive and negative points only
if (count(points > 0.) > 0) then
positive_average = sum(points, points > 0.) / count(points > 0.)
end if
 
if (count(points < 0.) > 0) then
negative_average = sum(points, points < 0.) / count(points < 0.)
end if
 
deallocate (points)
 
! Print result to terminal
write (*,'(a,g12.4)') 'Average = ', average_points
write (*,'(a,g12.4)') 'Average of positive points = ', positive_average
write (*,'(a,g12.4)') 'Average of negative points = ', negative_average
 
end program average
</syntaxhighlight>
 
 
{{प्रोग्रामिंग भाषा}}