Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

record, interrupt, open, семинар, выбор, disk, двоичный, function, calculator, test, object, system, сервер, навучальны зборнiк па праграмаванню, восьмеричный
 

for valuable work you must have JavaScript (allow active content)

Java. J.10. Nest of tasks. Operator While. Operator Break. Operator Continue

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.1     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=0;      int n=2;      int k=1;
      while (n>k)
      {
            zz=zz+1;
            n=n+5;
            k=k*2;
      }
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.2     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=0;      int n=1;
      while (zz<100)
      {
            zz=zz+n;
            n=n+1;
      }
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.3     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=1;
      while (zz<1000) zz=zz*2;
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.4     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=0;      int k=1;
      while (k<5)
      {
            if (k % 2 == 0) zz=zz-3;
            else zz=zz+5;
            k=k+1;
      }
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.5     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=1000;
      while (zz>10) zz=zz / 3;
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.6     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=1;      int k=1;
      while (k<5)
      {
            zz=zz*k;
            k=k+1;
      }
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.7     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=1;
      while (! (zz % 7 == 0)) zz=zz+1;
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.8     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int zz=0;
      boolean b1=true;
      while (b1)
      {
            zz=zz+1;
            b1=b1 & (zz<5);
      }
      return zz;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.9     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    for (int i=1; i<7; i++)
    {
        s+=1;
        if (i==3) break;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.10     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    for (int i=1; i<7; i++)
    {
        s+=i;
        if (s>5) break;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.11     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<100)
    {
        i+=1;
        s+=i;
        if (i>50) break;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.12     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<100)
    {
        i+=1;
        s+=i;
        if (i>10) break;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.13     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<20)
    {
        i+=1;
        while (s<30)
        {
            s+=i;
            if (s>10) break;
        }
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.14     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    for (int i=1; i<7; i++)
    {
        if (i>4) continue;
        s+=1;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.15     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    for (int i=1; i<7; i++)
    {
        if (s>10) continue;
        s+=i;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.16     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    for (int i=1; i<7; i++)
    {
        if (i % 2 == 1) continue;
        s+=i;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.17     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<10)
    {
        i+=1;
        s+=i;
        if (i>5) continue;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.18     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<10)
    {
        i+=1;
        if (i>2) continue;
        s+=i;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.19     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<10)
    {
        s+=i;
        if (i>2) continue;
        i+=1;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.20     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int i=0;
    while (s<7)
    {
        s+=i;
        if (i>2) continue;
        i+=1;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.10.21     Answer

Determine a value produced by function AA


int AA()
{
      int s=0;
      int i=0;
      while (s<7)
      {
            s+=i;
            if (i>3) continue;
            i+=1;
      }
      return s;
}



 

©   Aliaksandr Prykhodzka    1993 - 2007