Calculate the factorial of the first element of array, which value is less than 8
I have the completely code of example with question ( Enter the array of 10 integer numbers. Create the new array of the first array elements divided by the sum of its elements with odd indexes.)
In example included automation. I want to undestand, how to make my question, remaking the complete ex.
Code:
//---------------------------------------------------------------------------
#include <math.h>
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
randomize();
const int N=10; //constant N is for quantity elements in array
int a[N], i, sum=0; //a is the first array
float b[N]; //b is the new array
//int a[5]={-1,2,31,4,51};
for (i=0; i<N; i++)
{
a[i]=random(4);
StringGrid1->Cells[i][0]=FormatFloat("0.0",a[i]);
}
//a[i]=StrToInt(StringGrid1->Cells[i][0]); //read the value of elements from Cells of StringGrid with row 0 and
//column i
for (i=0; i<N; i++) //calculate the sum
if (i%2!=0)
sum+=a[i];
Edit1->Text=IntToStr(sum);
for (i=0; i<N; i++)
b[i]=1.*a[i]/sum; //divide elements a[i] by sum and assign the result to b[i]
for (i=0; i<N; i++)
StringGrid2->Cells[i][0]=FormatFloat("0.0",b[i]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit1->Clear();
}
//---------------------------------------------------------------------------
Image of program:
http://s020.radikal.ru/i702/1212/a6/509cc4ad05d6.png