teknikat e gjuheve te programimit-1

Upload: llazi-legjenda

Post on 06-Jul-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    1/120

    Teknikat e gjuheve te

    programimit

    UPT

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    2/120

    Programi

    Programi I pare ne gjuhen C

    Modifikimet dhe kontrolli i gabimeveKomentet

    Librarite

    Funksion main(Karakteret e Controllit

    Funksionet dhe programimi me module

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    3/120

    Programi I pare ne gjuhen C

    !" Program #$# % Para&itja e 'ello )orld* "!

    +in,lude -stdio$h.

    int main(void

    /

    printf(0ello 1orld203

    return 435

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    4/120

    Modifikimet dhe kontrolli i gabimeve

    +in,lude-stdio$h.

    int main(void

    /

    printf(“Gabimet ne gjuhen c!")

    return 43

    5

    Pas kompilimit

    67nta8 error 9 missing :3: before :5:

    ;LL 4 1arning(s

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    5/120

    Komentet

    #include  /* kjo eshte

    nje librari */ 

    int main(void)  /* funksioni kryesor*/ 

      illimi i mainitprintf(“$omentet!")% /* ky resht paraqet nje shprehje */ 

    return &% /* Perfundon programin */ 

    '

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    6/120

    Librarite

    +in,lude -stdio$h.

    +in,lude -math$h.

    +in,lude -string$h.

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    7/120

    Funksion main(

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    8/120

    Karakteret e Controllit

    +in,lude -stdio$h.

    int main(void

    /

    printf(0?nProgrami i pare ne ,$?nProgramoi 8888 7777$03

    return 43

    5?n @resht i ri?r ,arriage return?b ba,kspa,e?t tab horiAontal

    ?a sinjal?B B?0 ' ? ?? ba,kslash (?

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    9/120

    Funksionet dhe programimi me module

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    10/120

    Leksioni D = Eariablat

    Cfare eshte nje variabel

    Eariablat e numbraveInteger ;mertimi i variablave

    Ini,ialiAimi dhe perdorimiFloating=Point

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    11/120

    Perdorimi i variablave

    !" Program % Perdorimi i variablave"!

    +in,lude -stdio$h.

    int main(void

    /

    int salar73 !" deklarimi i variablit me emer salar7 "!

    salar7 #44443 !" vleredhenia "!

    printf('vlera 9 Gd$0> salar73return 43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    12/120

    shembuj

    +in,lude -stdio$h.

    int main(void

    /

    int TotalHPets3

    int Cats3

    int ogs3

    int Ponies3

    int

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    13/120

    Llojet e variablavesigned ,har # =#DN deri #DO

    short int D =D>ON deri D>OO

    int J =D>#JO>JN>JN deri D>#JO>JN>JOlong int J = D>#JO>JN>JN deri D>#JO>JN>JO

    long long int N =Q>DD>OD>4>NRJ>OOR>N4N deri

    Q>DD>OD>4>NRJ>OOR>N4O

    unsigned ,har # 4 deri DRR

    unsigned short int ose

    unsigned short D 4 deri R>RR

    unsigned int J 4 deri J>DQJ>QO>DQR

    unsigned long int ose unsigned long J 4 deri J>DQJ>QO>DQR

    unsigned long long int ose

    unsigned long long N 4 deri #N>JJ>OJJ>4O>O4Q>RR#>#R

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    14/120

    Float point

    float J S$J;N ( de,imal

    double N S#$O;4N (#R de,imal

    long double #D S#$#Q;JQD (#N de,imal

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    15/120

     rithmetika

    +in,lude -stdio$h.

    int main(void

    / float radius 4$4f3 /* The radius of the table */ float diameter 4$4f3 /* The diameter of the table */ 

    float ,ir,umferen,e 4$4f3 /* The circumference of the table */ 

    float area 4$4f3 /* The area of a circle */ 

    float Pi $#J#RQDRf3

    printf('iametri903

    s,anf(0Gf0> diameter3 /* Read the diameter from the keyboard */ 

    radius diameter!D$4f3 /* Calculate the radius */ 

    ,ir,umferen,e D$4f"Pi"radius3

    area Pi"radius"radius; /* Calculate the area */ 

    printf(0?nPerimetri eshte G$Df0> ,ir,umferen,e3printf(0?n6iperfa&ja G$Df?n0> area3

    return 43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    16/120

     rithmetika

    iametri 9

    Perimetri eshte #N$NR

    6iperfa&ja DN$DO

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    17/120

    +in,lude -stdio$h.

    int main(void

    /

    ,har first :T:3,har se,ond D43

    printf(0?nThe first e8ample as a letter looks like this = G,0> first3

    printf(0?nThe first e8ample as a number looks like this = Gd0> first3

    printf(0?nThe se,ond e8ample as a letter looks like this = G,0> se,ond3

    printf(0?nThe se,ond e8ample as a number looks like this = Gd?n0> se,ond3

    return 43

    5

    The output from this program is the follo1ing9

    The first e8ample as a letter looks like this = T

    The first e8ample as a number looks like this = NJ

    The se,ond e8ample as a letter looks like this = V

    The se,ond e8ample as a number looks like this = D4

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    18/120

    $arateriChar letter ::3

    Char digit :Q:3

    Char e8,lamation :2:3

    ,har ,h 43

    s,anf(0G,0> ,h3 !" @ead one ,hara,ter "!

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    19/120

    numerations

    enum )eekda7 /Monda7> Tuesda7> )ednesda7> Thursda7> Frida7>

    6aturda7> 6unda753

    enum )eekda7 toda7 )ednesda73

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    20/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    21/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    22/120

    op ( => "> !

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    23/120

    Funksionet matematik

    floor(8 @eturns the largest integer that isnYt greater than 8 as t7pe double

    ,eil(8 @eturns the smallest integer that isnYt less than 8 as t7pe double

    fabs(8 @eturns the absolute value of 8

    log(8 @eturns the natural logarithm (base e of 8

    log#4(8 @eturns the logarithm to base #4 of 8

    e8p(8 @eturns the value of e8s&rt(8 @eturns the s&uare root of 8

    double 8 D$DR3

    double less 4$43

    double more 4$43

    double root 4$43less floor(83 !" @esult is D$4 "!

    more ,eil(83 !" @esult is $4 "!

    root s&rt(83 !" @esult is #$R "!

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    24/120

    Leksioni

      Eendimet  Krahasimet aritmetike  If % else 

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    25/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    26/120

    Krahasimet aritmetike

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    27/120

    If 

    +in,lude -stdio$h.int main(void

    /int number 43

    printf(0?6hkruani nje numer 9 03

    s,anf(0Gd0>number3

    if(number . R printf('Zu shkruajtet Gd e ,ila eshte me e madhe se R?n0> number3

    if(number -

    printf(0 Zu shkruajtet Gd e ,ila eshte me e vogel se ?n 0> number3

    return 43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    28/120

    If % else

    If  (e8pression

    6tatement#3

    else6tatementD3

    e8tHstatement3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    29/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    30/120

    IF = ;L6;

    if(e8pression

    /

    6tatement#3

    6tatementD3

    $$$

    5

    else/

    6tatementW#3

    6tatementWD3

    $$$5

    e8tHstatement3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    31/120

    IF = ;L6;

    if(e8pression#

      /

    6tatement3

    if(e8pressionD

    6tatementW3

    else

    6tatementC35

    else

    6tatement3

    6tatement ;3

    < L jik

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    32/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    33/120

    letter3

    5

    elseprintf('Zu nuk sht7per nje shkronje te madhe$?n03

    return 43

    5

    < t t k ht

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    34/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    35/120

    lse f 

    if(,hoi,e#

    !" 6tatement or blo,k for ,hoi,e # "!

    else if(,hoi,eD

    !" 6tatement or blo,k for ,hoi,e D "!

    else if(,hoi,e

    !" 6tatement or blo,k for ,hoi,e D "!!" ^ and so on ^ "!

    else

    !" efault statement or blo,k "!

    6 it h

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    36/120

    61it,h

    s1it,h(integerHe8pression

    /

    ,ase ,onstantHe8pressionH#9

    statementsH#3

    break3

    $$$$,ase ,onstantHe8pressionHn9

    statementsHn3

    break3

    default9

    statements3

    5

    6 it h

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    37/120

    61it,h!" Lu,k7 Lotteries "!

    +in,lude -stdio$h.

    int main(void

    / int ,hoi,e 43

    printf(0?n]gjidhnji nje numer nga # tek #4 9 03

    s,anf(0Gd0>,hoi,e3

    s1it,h(,hoi,e

    /

    ,ase O9printf(0?nCongratulations203

    break3

    ,ase D9

    printf(0?n[ou 1in a pen$03

    break3default9

    printf(0?n6orr7> 7ou lose$?n03

    break3

    5

    return 43 5

    t

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    38/120

    goto

    goto there3

    6hembull 9+in,lude -stdio$h.

    int main(void

    /

    int i 4>s436huma9

    ssi3

    ii#3

    if (i-#4 goto 6huma3

    printf('Totali Gd*>s3

    return 43

    5

    < t t Wit

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    39/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    40/120

    Leksioni J = Ciklet

    Cfare jane ,iklet dhe si punojne

     

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    41/120

    b R kemi 8#R dhe 7#

      == ]vogelon vleren me #number==3 ose ==number3

    Cikli F

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    42/120

    Cikli F ,ount3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    43/120

    Cikli F

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    44/120

    Cikli F

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    45/120

    Cikli F

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    46/120

    Cikli F ans1er3

    if(tolo1er(ans1er :n:

    break3 !" Xo to statement after the loop "!

    5

    !" 6tatement after the loop "!

    Cikli )IL;

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    47/120

    Cikli )IL;

    )hile this ,ondition is true

    Keep on doing this

    1hile( e8pression

    6tatement#3

    6tatementD3

    Cikli )IL;

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    48/120

    Cikli )IL;

    Cikli )IL;

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    49/120

    Cikli )IL;

    +in,lude -stdio$h.

    int main(void

    /long sum 4L3

    int i #3

    int ,ount 43

    printf(0?n6hkruani 9 03

    s,anf(0 Gd0> ,ount3

    !" 6huma e numrave te plote nga # deri ne n"!

    1hile(i - ,ount

    sum i3

    printf(0Totali Gld?n0> sum3

    return 435

    Cikli o )hile

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    50/120

    Cikli o % )hile

    do

    6tatement31hile(e8pression3

    Cikli o )hile

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    51/120

    Cikli o % )hile

    int number J3

    1hile(number - J

    /printf(0?number Gd0> number3

    number3

    5

    int number J3

    do

    /

    printf(0?number Gd0> number3

    number3

    5

    1hile(number - J3

    Cikli o % )hile

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    52/120

    Cikli o % )hile

    !" @eversing the digits "!

    +in,lude -stdio$h.

    int main(void

    /

    int number 43 int rebmun 43

    int temp 43

    printf(0?n;nter a positive integer9 03

    s,anf(0 Gd0> number3

    temp number3do

    /

      rebmun #4"rebmun temp G #43

    temp temp!#43

    5 1hile(temp3 !" Continue 1hile temp.4 "!

    printf(0?n Gd reversed is Gd ?n'> number> rebmun 3return 43

    5

    Ciklet e kombinuara

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    53/120

    Ciklet e kombinuara

    for(int i 4 3 i-#4 3 i

    /

      for(int j 4 3 j-D4 3 k !" Loop e8e,uted #4 times "!/

    for(int k 4 3 k-4 3 k !" Loop e8e,uted #48D4 times "!

      /

    !" Loop bod7 e8e,uted #48D484 times "!

      !" o something useful "!

      5

    5

      5

    Ciklet e kombinuara

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    54/120

    Ciklet e kombinuara

    Te realiAohet programi i ,ili llogarit shumen e numrave nga # deri

    ne nje numer te dhene dhe e para&et ne formen e meposhteme 9

    #DJR #R+in,lude -stdio$h.

    int main(void

    / long sum #L3 int j #3 int ,ount 43

    printf(0?n;nter the number of integers 9 03 s,anf(0 Gd0> ,ount3

      for(int i # 3 i - ,ount 3 i  / sum #L3 j#3

    printf(0?n#03

      !" Llogaritja e shumes nga # ne i "!

      1hile(j - i

      / sum j3

    printf(0Gd0> j3 !"

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    55/120

    Eektoret

      /rogramimi pa vetore

      0fare eshte nje vetor 

      /erdorimi i vetoreve

      1emorja dhe 2dresat

      niciali3imi i nje vetori

      4etoret 1ultidimensional

    /rogramimi pa vetore

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    56/120

    /rogramimi pa vetore

    +in,lude -stdio$h.

    int main(void

    /

    int number 43

    int ,ount #43

    long sum 4L3

    float average 4$4f3 !" Mesatarja "!

     !" Le8imi i numrave per llogaritjen e mesatares "!

    for(int i 43 i - ,ount3 i

      /

    printf('6hkruani numrin Gd9 0> i3

    s,anf(0Gd0> number3

    sum number3

    5

    average (floatsum!,ount3 !" Mesatarja "!printf(0?nMesatarja e #4 numrave &e ju futet Gf?n0> average3

    return 43

    5

    0fare eshte nje vetor

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    57/120

    0fare eshte nje vetor 

    long numbers#43

    /erdorimi i vetoreve

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    58/120

    /erdorimi i vetoreve+in,lude -stdio$h.

    int main(void

    /

    int numbers#43 !" Eektor per #4 numra "!int ,ount #43 !" umri i elementeve per le8im"!

    long sum 4L3 !" 6huma e numrave"!

    float average 4$4f3 !" Mesatarja "!

    printf(0?n6hkruani #4 numrats9?n03

    !" Le8imi i numrave nga tastjera"!

    for(int i 43 i - ,ount3 i   /

    printf(0GDd. 0>i#3

    s,anf(0Gd0> numbersi3

    sum numbersi3

    5

    average (floatsum!,ount3

    printf(0?nMesatarja Gf?n0> average3

    return 43

    5

    1emorja dhe 2dresat

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    59/120

    1emorja dhe 2dresat+in,lude-stdio$h.

    int main(void

    /

    !" de,lare some integer variables "!long a #L3

    long b DL3

    long , L3

    printf(0 variable of t7pe long o,,upies Gd b7tes$0> siAeof(long3

    printf(0?nere are the addresses of some variables of t7pe long903

    printf(0?nThe address of a is9 Gp The address of b is9 Gp0> a> b3printf(0?nThe address of , is9 Gp0> ,3

    return 43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    60/120

    1emorja dhe 2dresat

    1emorja dhe 2dresat

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    61/120

    1emorja dhe 2dresat

    int dataR3

    for(int i 4 3 i-R 3 i

    / datai #D"(i#3

     printf(0?ndataGd ddress9 Gp Contents9 Gd0> i> datai> datai3

    5

    data4 ddress9 4844#DffRN Contents9 #D

    data# ddress9 4844#DffR, Contents9 DJ

    dataD ddress9 4844#Dff4 Contents9

    data ddress9 4844#DffJ Contents9 JN

    dataJ ddress9 4844#DffN Contents9 4

    niciali3imi i nje vetori

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    62/120

    niciali3imi i nje vetori

    double valuesR / #$R> D$R> $R> J$R> R$R 53

    !! ini,ialiAim i plote

    double valuesR / #$R> D$R> $R 53

    !! ini,ialiAim i pjesshem

    int primes / D> > R> O> ##> #> #O> #Q> D> DQ53

    !! ini,ialiAim i paper,aktuar 

    4etoret 1ultidimensional

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    63/120

    4etoret 1ultidimensional

    float numbersR3

    4etoret 1ultidimensional

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    64/120

    4etoret 1ultidimensional

    4etoret 1ultidimensional niciali3imi

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    65/120

    4etoret 1ultidimensional niciali3imi

    int numbersJ /

    / #4> D4> 4> J4 5> !" @eshti i pare "!

    / #R> DR> R> JR 5> !" @eshti i d7te "!

    / JO> JN> JQ> R4 5 !" @eshti i trete"!

      53

    6tring

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    66/120

    g

      0fare eshte nje 5tring6

      4eprimet me 5tringe

      4etoret e 5tringave

      unsionet e librarise 5tring

      7ransformimi i 5tringave

    0fare eshte nje 5tring

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    67/120

    j g

    printf(0This is a string$03

    printf(0This is on?nt1o lines203

    printf(0For ?0 7ou 1rite ???0$03

    0fare eshte nje 5tring

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    68/120

    j g

    +in,lude -stdio$h.

    int main(void

    /printf(0The ,hara,ter ?4 is used to terminate a string$03

    return 43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    69/120

    j g

    ,har sa7ing 0This is a string$03

    +in,lude -stdio$h.

    int main(void/

    ,har str# 0To be or not to be03

    ,har strD 0>that is the &uestion03

    int ,ount 43 !" 6tores the string length "!

    1hile (str#,ount 2 :?4: !" In,rement ,ount till 1e rea,h the string "!

    ,ount3 !" terminating ,hara,ter$ "!printf(0?nThe length of the string ?0Gs?0 is Gd ,hara,ters$0> str#> ,ount3

    ,ount 43 !" @eset to Aero for ne8t string "!

    1hile (strD,ount 2 :?4: !" Count ,hara,ters in se,ond string "!

    ,ount3

    printf(0?nThe length of the string ?0Gs?0 is Gd ,hara,ters$?n0> strD> ,ount3

    return 435

    The length of the string 0To be or not to be0 is #N ,hara,ters$

    The length of the string 0>that is the &uestion0 is D# ,hara,ters$

    4eprimet me 5tringe

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    70/120

    p g

      *ashimi i 5tringave

    +in,lude -stdio$h.

    int main(void/

    ,har str#J4 0To be or not to be03

    ,har strD 0>that is the &uestion03

    int ,ount# 43 int ,ountD 43

    1hile (str#,ount# ,ount#3

    1hile (strD,ountD ,ountD3if(siAeof str# - ,ount# ,ountD #

    printf(0?n[ou ,an:t put a &uart into a pint pot$03

    else

      / ,ountD 43

    1hile(strD,ountD str#,ount# strD,ountD3

    str#,ount# :?4:3

    printf(0?nGs?n0> str# 3

    5

    return 43 5

    4etoret e 5tringave

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    71/120

    g

    ,har sa7ingsD /

    'Fjalia #$0>

    'Fjalia D$0>'Fjali tjeter$0

      53

    for(int i 4 3 i- 3 i/

      printf(0?nGs0> sa7ingsi3

    5

    unsionet e librarise 5tring

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    72/120

    g

    +in,lude -string$h.

      str,p7(string#> stringD3  ,ountD strlen(strD3  str,at(str#> strD3 ose strn,at(str#> strD> R

      str,mp(str#> strD3  str,hr(str> ,3  strstr(te8t> 1ord3

    str,p7(string#> stringD3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    73/120

    p7( g g

    if(siAeof(stringD - siAeof (string#

    str,p7(string#> stringD3

    ,har destination 0This string 1ill be repla,ed03,har sour,e 0This string 1ill be ,opied in part03

    siAeHt n D3 !" umber of ,hara,ters to be ,opied "!

    strn,p7(destination> sour,e> n3

    strlen(strD3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    74/120

    (

    1hile (strD,ountD

    ,ountD3

    strD3

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    75/120

    (

    ,ountD 43

    1hile(strD,ountD

    str#,ount# strD,ountD3

    str#,ount# :?4:3

    str,at(str#> strD3

    strD> R3

    Krahasimi i stringave

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    76/120

    ,har str# 0The &ui,k bro1n fo803

    ,har strD 0The &ui,k bla,k fo803

    if(str,mp(str#> strD - 4  printf(0str# is less than strD03

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    77/120

    Pointer 

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    78/120

      Cfare eshte nje pointer dhe si perdoret

      dr7shimi midis pointerit dhe vektorit

      Perdorimi i pointerave me string

      6i mund te deklarojme dhe te perdorim vektor

    pointerash

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    79/120

    Cfare eshte nje pointer dhe si perdoret

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    80/120

    +in,lude -stdio$h.

    int main(void

    /int number 43

    int "pointer ULL3

    number #43

    printf(0?nnumber:s address9 Gp0> number3 !"

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    81/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    82/120

    "pointer DR3 pointer anotherHnumber3 "pointer DR3

    +in,lude -stdio$h.

    int main(void/

    long num# 4L3

    long numD 4L3

    long "pnum ULL3

    pnum num#3 !" Xet address of num# "!

    "pnum D3 !" 6et num# to D "!numD3 !" In,rement numD "!

    numD "pnum3 !" dd num# to numD "!

    pnum numD3 !" Xet address of numD "!

    "pnum3 !" In,rement numD indire,tl7 "!

    printf('?nnum# Gld numD Gld "pnum Gld "pnum numD Gld?n0>

    num#> numD> "pnum> "pnum numD3return 43

    5

    num# D numD J "pnum J "pnum numD N

    dr7shimi midis pointerit dhe vektorit

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    83/120

    ,har single3

    s,anf(0G,0> single3

    ,har multiple#43

    s,anf(0Gs0> multiple3

    int main(void

    /

    ,har multiple 0M7 string03,har "p multiple43

    printf(0?nThe address of the first arra7 element 9 Gp0> p3

    p multiple3

    printf(0?nThe address obtained from the arra7 name9 Gp?n0> p3

    return 43

    5

    The address of the first arra7 element 9 4844#ffD

    The address obtained from the arra7 name9 4844#ffD

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    84/120

    Eektor pointerash

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    85/120

    ,har namesRD4/ /0Xeorge05>

      /::Mi,hael05>

      /0Zoe05>

      /0Mar,us05>

      /06tephanie05 53

    ,har "namesR/ /0Xeorge05>  /0Mi,hael05>

    /0Zoe05>

      /0Mar,us05>

      /06tephanie05 53

    printf(0Gs0> "names3 !" Prints Xeorge "!

    printf(0Gs0> "(names#3 !" Prints Mi,hael "!

    6trukturimi i programit

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    86/120

    8apsira e variablave

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    87/120

    /

    int a 43 !" Create a "!

    !" @eferen,e to a is

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    88/120

    +in,lude -stdio$h.

    int main(void/

    int ,ount# #3 !" e,lared in outer blo,k "!

    do

    /

    int ,ountD 43 !" e,lared in inner blo,k "!

    ,ountD3printf(0?n,ount# Gd ,ountD Gd0> ,ount#>,ountD3

    5 1hile( ,ount# - N 3

    !" ,ountD no longer e8ists "!

    printf(0?n,ount# Gd?n0> ,ount#3

    return 43

    5

    unsionet

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    89/120

    @eturnHt7pe Fun,tionHname ( Parameterat

    /

      6tatements3

    5

    unsionet

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    90/120

    +in,lude -stdio$h.

    !" efinition of the fun,tion to ,al,ulate an average "!

    float average(float 8> float 7

    /return (8 7!D$4f3

    5

    !" main program = e8e,ution al1a7s starts here "!

    int main(void

    /

    float value# 4$4F3 float valueD 4$4F3 float value 4$4F3printf(0;nter t1o floating=point values separated b7 blanks9 03

    s,anf(0Gf Gf0> value#> valueD3

    value average(value#> valueD3

    printf(0?nThe average is9 Gf?n0> value3

    return 43

    5

    ;nter t1o floating=point values separated b7 blanks9 D$J J$RO

    The average is9 $JRR44

    MekaniAmi i parametrave

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    91/120

    unsionet

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    92/120

    +in,lude -stdio$h.float average(float> float3 !" Fun,tion protot7pe "!

    int main(void

    /

    !" Code in main( $$$ "!5

    float average(float 8> float 7

    /

    return (8 7!D$43

    5

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    93/120

    @ekursiviteti

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    94/120

    void Looper(void

    /

    printf(0?nLooper fun,tion ,alled$03

    Looper(3 !" @e,ursive ,all to Looper( "!

    5

    @ekursiviteti

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    95/120

    +in,lude -stdio$h.

    unsigned long fa,torial(unsigned long3

    int main(void

    /

    unsigned long number 4L3

    printf(0?n;nter an integer value9 03

    s,anf(0 Glu0> number3

    printf(0?nThe fa,torial of Glu is Glu?n0> number> fa,torial(number3

    return 435

    !"

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    96/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    97/120

    6truktura

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    98/120

     Cfare jane 6trukturat

     6i deklarohet nje strukture

     Perdorimi struktures

     Eektore e llojeve stru,t

    6tru,turastru,t structure tag

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    99/120

    stru,t structure tag 

      /

      member definition;

      member definition;

      9

      member definition;

      5 one or more structure variables3

    stru,t student/

    int age3

    int group3

    ,har nameD43

    ,har fatherD43

    ,har motherD4353

    stru,t student st#>stD3

    6tru,tura+in,lude -stdio h.

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    100/120

    +in,lude -stdio$h.

    int main(void

    /

    stru,t student !" 6tru,ture de,laration "!

    /int age3

    ,har nameD43 ,har fatherD43

    ,har motherD43 53

    stru,t student st#3 !" 6tru,ture variable de,laration "!

    !" InitialiAe the stru,ture variable from input data "!

    printf(0;nter the name 9 0 3 s,anf(0Gs0> st#$name3 !" @ead the student:s name "!

    printf(0o1 old is GsB 0> st#$name 3 s,anf(0Gd0> st#$age 3 !" @ead age "!

    printf(0)ho is Gs:s fatherB 0>st#$name 3 s,anf(0Gs0>st#$father 3 !"the father:s name "!

    printf(0)ho is Gs:s motherB 0> st#$name 3 s,anf(0Gs0> st#$mother 3

    !" o1 tell them 1hat 1e kno1 "!

    printf(0?nGs is Gd 7ears old'>st#$name> st#$age3

    printf(0 and has Gs and Gs as parents$?n0> st#$father>at#$mother 3return 43

    5

    6tru,tura+i l d tdi h

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    101/120

    +in,lude -stdio$h.

    int main(void

    / int nr>i3

    stru,t student !" 6tru,ture de,laration "!/

    ,har emriD43

    ,har mbieriD43

    53

    stru,t student st#443 !" 6tru,ture variable de,laration "!

    printf('6hkruani nr e studenteve9 0 3 s,anf(0Gd0> nr3

    for (i43i-nr3i

      /

      printf(';mri i studentit Gd 0> i# 3 s,anf(0Gs0> sti$name3

    printf('Mbiemri i studentit Gd 0> i# 3 s,anf(0Gs0> sti$mbieri3

    5

    return 43

    5

    6tru,tura

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    102/120

    stru,t student

    /

    stru,t ate/

    int da73

    int month3

    int 7ear3

    5 dob3

    ,har nameD43

    ,har fatherD43

    ,har motherD43

    53

    6tru,tura+in,lude -stdio h.

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    103/120

    +in,lude -stdio$h.

    stru,t student

    / ,har stameDR3

      ,har grade3

      int age3  float average3 53

    main(

    /

      stru,t student std# /::Zoe Wro1n0> ::> #> Q#$J53

      stru,t student stdD> std3 !" ot initialiAed "!

      stdD std#3 !" Copies ea,h member of std# "!  std std#3 !" to stdD and std "!

      printf(0The ,ontents of stdD9?n03

      printf(0Gs> G,> 0> stdD$stame> stdD$grade3

      printf(0Gd> G$#f?n?n0> stdD$age> stdD$average3

      printf(0The ,ontents of std9?n03

      printf(0Gs> G,> 0> std$stame> std$grade3

      printf(0Gd> G$#f?n0> std$age> std$average3  return 43

    5

    File

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    104/120

    Cfare eshte nje file

    6i perdoren file=at

    6hkrimi dhe le8imi mbi file

    File=at temporar7

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    105/120

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    106/120

    /erdorimi i fileve te,t

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    107/120

    int fput,(int ,> FIL; "pfile35hrimi 

    m,har   fget,(pfile39e,imi 

    /erdorimi i fileve+in,lude -stdio$h.

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    108/120

    +in,lude stdio$h

    +in,lude -string$h.

    +in,lude -stdlib$h.

    ,onst int L;XT N43

    int main(void

    /

    ,har m7strL;XT3 int lstr 43

    int m7,har 43 FIL; "pfile ULL3 ,har "filename 0C9??m7file$t8t03

      printf(0?n6hkruani nje shprehje 9?n03 gets(m7str3

    if(2(pfile fopen(filename> 010  / printf('gabim ne hapjen e file=it Gs$0> filename3 e8it(#3 5

      lstr strlen(m7str3

      for(int i lstr=# 3 i . 4 3 i==

    fput,(m7stri> pfile3

    f,lose(pfile3

    if(2(pfile fopen(filename> 0r0/ printf(0 gabim ne hapjen e file=it Gs$0> filename3 e8it(#3 5

      1hile((m7,har fget,(pfile 2 ;

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    109/120

    int fputs(,har "pstr> FIL; "pfile3

    ,har "fgets(,har "pstr> int n,hars> FIL; "pfile3

    fprintf(pfile> 0G#DdG#DdG#Jf0> num#> numD> fnum#3

    fs,anf(pfile> 0G#DdG#DdG#Jf0> num#> numD> fnum#3

    File=at binar 

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    110/120

    Perdorimi i file=ve binar 

    5h i i

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    111/120

    ,har "filename 0m7file$bin03

    FIL; "pfile fopen(filename> 01b03

    long pdata /DL> L> JL53

    int numHitems siAeof(pdata!siAeof(long3FIL; "pfile fopen(filename> 01b03

    siAeHt 1,ount f1rite(pdata> siAeof(long> numHitems> pfile3

    5hrimi 

    Perdorimi i file=ve binar 

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    112/120

    9e,imi 

    fread( pdata> siAeof(long> numHitems> pfile3

    PoAi,ionimi ne file

    / i i i t l

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    113/120

    long ftell(FIL; "pfile3 fpos ftell(pfile3

    /o3icioni atual

    int fseek(FIL; "pfile> long offset> int origin3

    /o3icioni i ri

    File=at+in,lude -stdio$h.

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    114/120

    +in,lude stdio$h

    +in,lude -,t7pe$h.

    +in,lude -stdlib$h.

    +in,lude -string$h.!" Xlobal ata "!

    ,onst int M;HMc D43

    stru,t

    /

    ,har "filename3 !" Ph7si,al file name "!

    FIL; "pfile3 !" File pointer "!5 global /0C9??m7file$bin0> ULL 53

    !" 6tru,ture t7pes "!

    stru,t ate !" 6tru,ture for a date "!

    /

    int da73int month3

    int 7ear3

    53

    File=att7pedef stru,t famil7

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    115/120

    t7pedef stru,t famil7

    /

    stru,t ate dob3

    ,har nameM;HMc3,har paHnameM;HMc3

    ,har maHnameM;HMc3

    5Famil73

    bool getHperson(Famil7 "pfamil73 !" Input fun,tion "!

    void getname(,har "name3 !" @ead a name "!void sho1HpersonHdata(void3 !" 01b0/ printf(0?n Xabim me file Gs$?n0> global$filename3 e8it(#3 5

    File=at

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    116/120

    1hile(getHperson(member !" s long as 1e have input "!

    f1rite(member> siAeof member> #> pfile3 !" 1rite it a1a7 "!

    f,lose(global$pfile3 !" Close the file no1 its 1ritten "!

    sho1HpersonHdata(3 !" 6ho1 1hat 1e ,an find out "!

    5

    File=atbool get person(Famil7 "temp

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    117/120

    bool getHperson(Famil7 temp

    /

    stati, ,har more :?4:3 !" Test value for ending input "!

    printf(0?no 7ou 1ant to enter details of a person ([ or B '3s,anf(0 G,0> more3

    if(tolo1er(more :n: return false3

    printf(0?n;nter the name of the person9 03 gets(temp=.name3

    printf(0?n;nter Gs:s date of birth (da7 month 7ear3 0> temp=.name3s,anf(0Gd Gd Gd0> temp=.dob$da7> temp=.dob$month> temp=.dob$7ear3

    printf(0?n)ho is Gs:s fatherB 0> temp=.name3gets(temp=.paHname3

    printf(0?n)ho is Gs:s motherB 0> temp=.name3

    gets(temp=.maHname3

    return true3

    5

    File=atvoid sho1 person data(void

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    118/120

    void sho1HpersonHdata(void

    /

    Famil7 member3

    fposHt ,urrent 43if(2(global$pfile fopen(global$filename> 0rb0

    / printf(0?nUnable to open Gs$?n0> global$filename3 e8it(#3 5

    1hile(fread(member> siAeof member> #> global$pfile

    /

      fgetpos(global$pfile> ,urrent3 !" 6ave ,urrent position "!  printf(0?n?nGs:s father is Gs> and mother is Gs$0>

    member$name> member$paHname> member$maHname3

      getHparentHdob(member3 !" Xet parent data "!

      fsetpos(global$pfile> ,urrent3 !" Position file to read ne8t "!

    5

    f,lose(global$pfile3 !" Close the file "!5

    Temporar7

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    119/120

    FIL; "tmpfile(void3

    FIL; pfile3 !" File pointer "!

    pfile tmpfile(3 !" Xet pointer to temporar7 file "!

    ,har "tmpnam(,har "filename3File unike

    eader 

  • 8/17/2019 Teknikat e Gjuheve Te Programimit-1

    120/120