Search code examples
cc++builder-6

Show the number of min member of the progression


Need some help with code.

The task is "Show the number of min member of progression

{ a*i* }  a*i*= sinx+ 2*sin(1+2)*x +...+ i* sin(1+2+...+ i)*x ; i=[1;n]

I wrote code for finding min, but it does't work correctly.

My code :

void __fastcall TForm1::Button3Click(TObject *Sender){

 int i, j, n, y;
 float  x, a=0, num=0, min=sin(x) ;
 x = StrToFloat(Edit3->Text);
 n = StrToInt(Edit4->Text);
 j=0;
 for(i=1; i<=n; i++){
  j=j+i;
  y=i*sin((j)*x);
  if (y<min){
   min=y;
   num=i;
  }
  a=a+y;
}
Label3->Caption = "min: "+FloatToStr(num); }

Solution

  • Made this and it works)

    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
    int i, num, j=0, n;
    float x, a=0, y, min=100000 ;
    x = StrToFloat(Edit3->Text);
    n = StrToInt(Edit4->Text);
    for(i=1; i<=n; i++)
    {
    j=j+i;
    y=i*sin((j)*x);
    if (y<min)
    {
    min=y;
    num=i;
    }
    a=a+y;
    }
    Label3->Caption = "num: "+FloatToStr(num);
    }