سفارش تبلیغ
بزرگترین تونل شهری
;آموزش برتامه نویسی C - آموزش برنامه نویسی مبتدی برای دانشجویان


22/6/88
12:15 صبح

;آموزش برتامه نویسی C

بدست hsanali lotfi در دسته

<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} @font-face {font-family:Badr; panose-1:0 0 4 0 0 0 0 0 0 0;} @font-face {font-family:"Agency FB"; mso-font-alt:"Trebuchet MS";} /* 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 { text-indent:-18.0pt; font-family:Wingdings;} @list l0:level2 { margin-left:18.0pt; text-indent:-18.0pt; font-family:Wingdings;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} @font-face {font-family:Badr; panose-1:0 0 4 0 0 0 0 0 0 0;} @font-face {font-family:"Agency FB"; mso-font-alt:"Trebuchet MS";} /* 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 { text-indent:-18.0pt; font-family:Wingdings;} @list l0:level2 { margin-left:18.0pt; text-indent:-18.0pt; font-family:Wingdings;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

 


آرایه ها و ماتریس :


آرایه : مجموعه ای از عناصر هم نوع که به صورت پشت هم در حافظه ذخیره شده ولی دارای نام مشترکی می باشند , عناصر آن ها را با استفاده از شماره خانه (index) از یکدیگر متمایز می کنند .


 


 شکل کلی تعریف آرایه : 


                                                                             ; ] تعداد عناصر[ نام آرایه            نوع عناصر آرایه


       int                      n [3] ;                                                                                             


نکته : شاخص های آرایه در زبان C از صفر شروع می شوند .


مثال15) برنامه ای بنویسید که 10 نمره دانشجویی را گرفته و میانگین نمرات و خود نمرات را نمایش دهد.(حل توسط آرایه انجام شود .)


# include <stdio.h>


# include <conio.h>


Main( )


{


   Float mark [10];


   Float s , avg ;


   Int I ;


 For(i=0 ; i<=10 ; i++)


 {


     Printf("enter mark %d : " , i+1);


     Scanf(" %f \n " , & mark[i] );


     S+=mark[i];


 }// end of for


Avg= S /10;


Printf(" the avg = %5.2f ", avg );


For (I=0 ; I<=10 ; i++);


Prntf("the mark %d = %f " \n , i+1, mark [i] );


Getch( );


Return(0);


}


 


 


مثال 16) برنامه ای بنویسید که یک عضو را در یک آرایه ی n عضوی جست و جو کند .


 


 


# include <stdio.h>


# include <conio.h>


Main ( )


{


   Const int n=10;


    Int no[n];


    Int x,I,f=0;


    For (i=0;i<n;i++);


         Scanf("%d \n|",&n0[i]);


    Printf("enter any no for serch:");


    Scanf("%d \n "&x);


    For (i=0;i<n;i++);


    If (x==no[i]);


    {


       If=1;


     }


       Break;


       If(f==1)


              Printf("find");


       Else


              Prinff("not found");


 


   Getch( );


   Return (0);


}


}


مثال17 ) برنامه ای بنویسید که دو عدد بسیار یزرگ را با هم جمع کند.


 


# include <stdio.h>


# include <conio.h>


Main ( )


{


   Const int n=10;


    Int a[n],b[n],s[n];


    Int d,cary=10;


    For (i=0;i<10;i++)


    {


        Printf("enter %d digit no 1",i);


        Scanf ("%d \n ",&a[i]);


     }


     For (i=0;i<10;i++)


Printf("enter %d digit no2",i);


Scanf("%d \n",&b[n]);


For(i=9;i>=0;i--)


{


D=a[i]+b[i]+c;


If(d>=10)


{


S[i]=d-10;


C=1;


}


Else


{


S[i]=d;


C=0;


}


}


Printf("%d",c);


For(i=0;i<10;i++)


Printf("%d",s[i]);


Getch( );


Return( 0);


}


مثال18) برنامه ای بنویسید که عناصردو آرایه n عضوی را مشخص کند با هم برابرند یا نه ؟


 


# include <stdio.h>


# include <conio.h>


Main( )


{


   Const int n ;


   Float a[i],b[i];


   Intc     I,c;


   For(i=0;i<n;i++)


      {


         Printf("\n enter a[i],b[i]");


         Scanf("%f %f ",& a[i],& b[i] );


         If (a[i] = = b[i])


             C+ +;


       }


      If (c = = n)


          Printf(" \n yes ");


      Else


          Printf(" \n No ");


          Getch( );


           Return (0) ;


}