Struktura perseritese" while ".

 

Shembull per strukturat for, while dhe do-while



     // Printimi i numrave nga 1 ne 10 duke perdorur secilen strukture:

 

# include <iostream>

using namespace std;

int main()

{

int i = 1;

 

cout <<"while"<<endl<<endl;

while (i<= 10)

{

cout << i<<endl;

i = i+1;

}

 

cout <<"do while"<<endl<<endl;

i= 1;

do

{

cout << i<<endl;

i = i+1;

}while (i<= 10);

 

 

cout <<"for"<<endl<<endl;

 

for (i = 1 ; i<=10;i=i+1)

cout << i<<endl;

 

system("pause");

return 0;

}

                  



     // LLogaritja e numrit te mbetesave dhe kaluesve

#include <iostream>

using namespace std;   

int main()

{

int nr,mbetes = 0, kalues = 0;

cout << " Jepni noten"<<endl;

cin>> nr;

while (nr>0)

{

    if (nr<4)

    cout <<"Nr i gabuar"<<endl;

    else if (nr==4)

    mbetes++;

    else if (nr<=10)

    kalues++;

    else

     cout <<"Nr i gabuar"<<endl;

   

    cout << " Jepni note tjeter ose -1"<<endl;

    cin>> nr;

  }

 

    cout <<"Mbetes ="<<mbetes

    <<"Kalues = "<<kalues<<endl;

    if (kalues>mbetes)

     cout <<"Klase e mire"<<endl;

     else

     cout<<"Klase jo e mire"<<endl;

      system ("pause");

     return 0;

 

}



     Shembull i struktures for.

                  

// Fig. 2.21: fig02_21.cpp

// Llogarit dhe afishon sa do te jete llogaria

// lekeve ne nje banke per cdo vit per n vite te dhene

// me interes te caktuar.

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

   double llogaria_fund, // llogaria perfundimtare

          llogaria  ,  // llogaria fillestare

          interesi;// interesi

      int    n; //numri i viteve        

cout<<"Jepni llogarine fillestare"<<endl;

cin>>llogaria;

cout<<"Jepni numrin e viteve"<<endl;

cin>>n;

cout<<"Jepni interesin ne perqindje"<<endl;

cin>>interesi;

   cout << "viti" << setw( 21 )

        << "Llogaria" << endl;

       

cout<< fixed<< setprecision( 2 );

 

   for ( int viti = 1; viti <= n; viti++ ) {

llogaria_fund = llogaria * pow( 1.0 + interesi/100.0, viti );

      cout << setw( 4 ) << viti

           << setw( 21 ) 

           << llogaria_fund << endl;

   }

  

system("pause");

   return 0;

}