2020-10-20
  • |
  • daafoor
  • |
  • مشاهدات: 1009

حلقة Do :

يتيح بناء حلقة do تنفيذ عبارة أو سلسلة من العبارات بشكل تكراري ، بينما يكون شرط معين صحيحًا.

 

مثال حساب العاملة Factorial :

! compute factorials
do n = 1, 10
   nfact = nfact * n  
   ! printing the value of n and its factorial
   print*,  n, " ", nfact   
end do

 

مثال طباعة الاعداد من 11 الى 20 :

program printNum 
implicit none  

   ! define variables
   integer :: n
   
   do n = 11, 20     
      ! printing the value of n 
      print*,  n 
   end do 
   
end program printNum  

 

مثال عن ايجاد العاملة Factorial للاعداد من 1 الى 10 :

program factorial  
implicit none  

   ! define variables
   integer :: nfact = 1   
   integer :: n  
   
   ! compute factorials   
   do n = 1, 10      
      nfact = nfact * n 
      ! print values
      print*,  n, " ", nfact   
   end do 
   
end program factorial 

 

الخرج :

1             1
2             2
3             6
4            24
5           120
6           720
7          5040
8         40320
9        362880
10       3628800

هل أعجبك المحتوى؟

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!

التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول