Strukturat Ciklike, Tabelat dhe Funksionet · Vektoret Vektori eshte nje bashkesi variablash qe...
Transcript of Strukturat Ciklike, Tabelat dhe Funksionet · Vektoret Vektori eshte nje bashkesi variablash qe...
Mesimi 4.13
Strukturat Ciklike Perdoren per perseritjen e nje veprimi ose bashkesi
veprimesh.
Strukturat ciklike kryesore jane:
For
While
Do … While
Strukturat Ciklike - For Perdoret kur numri i cikleve eshte i paracaktuar.
Sintaksa: for(vlera filestare e numeruesit; kushti dhe vlera perfundimtare; hapi rrites ose zbrites)
{
Blloku i veprimeve;
}
Psh:
for(i=1; i<=10; i++)
shuma = shuma + i;
Vektoret Vektori eshte nje bashkesi variablash qe kane te
perbashket llojin, emrin, por ndryshojne ne indeks.
Numri i elementeve te vektorit eshte i paracaktuar dhe i fundem.
Psh: unsigned short int Nota1, Nota2, Nota3, … , Nota 30;
unsigned short int Nota[30];
Deklarimi i Vektorit Sintaksa:
lloji emri[numri i elementeve];
Psh:
unsigned short int nota[50];
float mesatarja[5];
Leximi Shkrimi i Vektorit Sintaksa per lexim:
for(i=1; i<=50; i++)
cin>>Nota[i];
Sintaksa per shkrim:
for(i=1; i<=50; i++)
cout>>Nota[i];
Nota[1] Nota[2] Nota[3] …. …. Nota[49] Nota[50]
8 9 10 … … 10 6
Shembull - 1
Shembull – 2:
Shembull – 3:
Shembull – 4:
Funksionet Funksionet sherbejne per te strukturuar me mire nje
program.
Secili prej tyre kryen nje detyre specifike.
Sintaksa e Funksionit Tipi_qe_kthen_funksioni emri_funksionit(tipi_parametrit emri_parametrit, …)
{
Instruksionet qe do te kryhen;
Vlera qe do te ktheje funksioni;
}
Funksioni qe kthen vleren maksimale Psh:
int max (int num1, int num2)
{
int rezultati;
if(num1>num2)
rezulati=num1;
else
rezulati=num2;
return rezultati;
}
Shembull - 3
Shembull – 3 (Vazhdim)