<!-- /* Font Definitions */ @font-face {font-family:Badr; panose-1:0 0 4 0 0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; font-size:14.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {} @list l0:level1 { margin-left:48.9pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->
مثال 13) برنامه ای بنویسید که تعدادی عدد را خوانده و کوچکترین و بزرگترین آنها را محاسبه کند .
# include <stdio.h>
# include <conio.h>
Main( )
{
Int n , max , min ;
Clrscr( );
Printf("enter first number :");
Scanf("%d \n",&n);
Max=n;
While(n!=0)
{
Printf("enter any number :");
Scanf(%d \n ,&n);
If (n>max)
Max=n;
Else
If (n<min)
Min=n;
}
Printf("max=%d,min=%d",max,min);
Getch ( );
Return(0);
}
2-2-2 – حلقه do – while : شکل کلی آن به صورت زیر است :
do do
دستور{ات} ; { printf (" %d" , i )
while (شرط(ها)) ; i++ ; }
while ( i <= 3) ;
نکته : در do – while شرط , انتهای کار تست می شود بنابراین دستورات داخل حلقه حداقل یکبار انجام می شود.
مثال 14 ) برنا مه ای بنویسید که تعدادی عدد را خوانده و زوجها و فرد های آن را بشما رد .( شرط اتمام وارد کردن عدد صفر میبا شد ) .
# include <htdio.h>
# include <conio.h>
Main( )
{
Int no,oc,oc,c;
Clrscr( )
Oc=0,c=0; = do
Printf("enter first no:"); {
Scanf("%d\n",&no); printf(" enter any no:");
While (no!=0) scanf("%d \n" , &no);
{ c++;
C++; if((no %2)==0)
If ((no%2)==0) oc++;
Oc++; }
Printf("enter any no:"); while(no!=0)
Scanf(" %d \n ", &no); oc--;
} c--;
Oc = c - oc;
Printf ("the oc= %d,the oc= %d \n ,oc,oc);
Getch( );
Return(0);
}
}