Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

sheet, variable, NTFS, многомерный, address, обзор, select, переход, computer, examples, shr, отчет, электронный репетитор, параметр, язык программирования
 

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

Java. J.15. Nest of tasks. Tasks on slicing

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.1     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2, int F3)
{
    int a=F1;    int b=F2;    int c=F3;
    int s1=a+b;
    int s2=b+c;
    int tt=s1+b;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.2     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2)
{
    int a=F1;    int b=F2;
    int tt=a*a;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.3     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=5;    int b=7;
    a=a*a;
    int tt=b-4;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.4     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2, int F3, int F4)
{
    int a=F1;    int b=F2;
    int c=F3;    int d=F4;
    int s1=a+b;
    int s2=b+c;
    int s3=c+d;
    int tt=s3-s1;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.5     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2, int F3, int F4)
{
    int a=F1;    int b=F2;
    int c=F3;    int d=F4;
    int s1=a+b+c;
    int s2=b+c+d;
    int tt=s1+s2;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.6     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1)
{
    int a=F1;
    int b1=a;
    int b2=a*a;
    int b3=a*a*a;
    int tt=b1+b2+b3;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.7     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2)
{
    int a=F1;    int b=F2;
    int c;
    if (a>b) c=a+b;
    else c=a-b;
    int tt=a+b;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.8     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2)
{
    int a=F1;    int b=F2;
    int c=0;
    for (int d=1; d     int tt=a+b;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.9     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2)
{
    int a=F1;    int b=F2;
    int c=0;
    for (int d=1; d     int tt=a+c;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.10     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA(int F1, int F2)
{
    int a=F1;    int b=F2;
    int c=0;
    for (int d=1; d     int tt=c+a;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.11     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int c=0;
    int a;    int b;
    for (int i=1; i<4; i++)
    {
        a=i+c;
        b=a*a;
        c=a+3;
    }
    int tt=c+5;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.12     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int tt=0; int c=5;
    int a;
    for (int i=1; i<4; i++)
    {
        a=i+c;
        tt=tt+a;
    }
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.13     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int tt=0;    int a=0;
    for (int i=1; i<8; i++) a=a+3;
    tt=tt+a;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.14     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int tt;
    tt=0;
    for (int i=1; i<8; i++) tt=tt+i;
    tt=51;
    while (tt>3) tt=tt / 3;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.15     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a1=1;
    int a2=2;
    int a3=a1+a2;
    int a4=a2+10;
    int a5=a2+a3;
    int a6=a1*a1;
    int tt=a4-a6;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.16     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=9;        int b=19;
    int c;
    if (a>b) c=1;
    else c=5;
    int tt=a-b;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.17     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=7;        int b=17;
    int c=0;        int d=0;
    if (a>b) c=a+b;
    else d=a*b;
    int tt=a+d;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.18     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=7;        int b=19+a;
    int c=a*a;    c=c+a;
    int x=0;
    while (c>a)
    {
        x=x+c;
        a=a-1;
    }
    int tt=x*x;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.19     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=1;        int tt=4;
    if (a==1) a=2;
    else
        if (a==2) a=3;
        else
            if (a==3) a=4;
            else
                if (a==4) tt=55;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.20     Answer      Pascal-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of function


int AA()
{
    int a=1;        int tt=4;
    if (a>50) a=50;
    else
        if (a>40) a=40;
        else
            if (a>30) a=30;
            else
                if (a>20) tt=5;
                else tt=6;
    return tt;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.21     Answer      Pascal-analogue      Visual Basic-analogue

Throw out redundant operators to produce the function of finding maximum element in array


int AA(int[] FF)
{
    int[] A = new int[11];
    for (int i=1; i<11; i++) A[i]=FF[i];
    int tt=A[1];    int aa=A[1];    int bb=A[1];
    for (int i=2; i<11; i++)
    {
        if (A[i]>tt) tt=A[i];
        if (A[i]==aa) aa=A[i];
        if (A[i]<bb) bb=A[i];
    }
    int Res;
    Res=tt;        Res=aa;    Res=bb;
    return Res;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.22     Answer      Pascal-analogue      Visual Basic-analogue

Throw out redundant operators to produce the function of finding maximum element in array


int AA(int[] FF)
{
    int[] A = new int[11];
    for (int i=1; i<11; i++) A[i]=FF[i];
    int tt=A[1];    int aa=A[1];    int bb=A[1];
    for (int i=2; i<11; i++)
    {
        if (A[i]>tt) tt=A[i];
        else
            if (A[i]==aa) aa=A[i];
            else
                if (A[i]<bb) bb=A[i];
    }
    int Res;
    Res=tt;        Res=aa;    Res=bb;
    return Res;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.15.23     Answer      Pascal-analogue

Throw out redundant operators to produce the function of finding maximum element in array


int AA(int[] FF)
{
      int[] Dragon = new int[11];
      for (int i=1; i<11; i++) Dragon[i]=FF[i];
      int tt=Dragon[10];
      for (int i=1; i<11; i++)
            if (Dragon[i]>tt) tt=Dragon[i];
      int k;
      while (Dragon[10]>0)
      {
            for (int i=9; i>0; i--)
                  Dragon[i+1]=Dragon[i+1]-Dragon[i];
            for (int i=9; i>0; i--)
                  for (int j=1; j<i+1; j++)
                        if (Dragon[j]>Dragon[j+1])
                        {
                              k=Dragon[j];
                              Dragon[j]=Dragon[j+1];
                              Dragon[j+1]=k;
                        }
            Dragon[10]=Dragon[9];
      }
      return tt;
}


 

©   Aliaksandr Prykhodzka    1993 - 2007