Posted by: default061 March 14, 2011
Login in to Rate this Post:
1
?
Liked by
here is the pseudocode by prankster with lil explanation,
double first[10] = {1.2,1.3,5.6.......................} // initialization of first array with 10 blocks ( 0 to 9 index)
double second[10] = {2.3, 4.2, 5.3,....................}//// initialization of second array with 10 blocks ( 0 to 9 index)
double product[10]; // declaration of third array that will store final result, it has 10 blocks too
for (int i=0;i<10;i++) // value of 'i' starts from 0 and goes up to 9, when 'i' reaches 10 , condition i<10 fails so loop terminates
{
product[i] = first[i] * second[i] //value stored at 'i' index of product = value of 'i' index of first array * value of 'i' index of second array
}
that for loop would be :
product[0]=first[0]*second[0] = 1.2*2.3= ..
product[1]=first[1]*second[1]=1.3*4.2=..
and continues up to product[9]=first[9]*second[9]=....
What you can add:
Declare String before for loop : ex String result=" ";
Inside for loop , style the output for arraays and concat it to the result :
ex, result=result+" "+ first[i]+" * "+second[i]+" =" +product[i] + "\n" ;
// this will collect all your contents of array in one string , ie result
Now you can display result in one line using whatever is required, just display that string "result"
double first[10] = {1.2,1.3,5.6.......................} // initialization of first array with 10 blocks ( 0 to 9 index)
double second[10] = {2.3, 4.2, 5.3,....................}//// initialization of second array with 10 blocks ( 0 to 9 index)
double product[10]; // declaration of third array that will store final result, it has 10 blocks too
for (int i=0;i<10;i++) // value of 'i' starts from 0 and goes up to 9, when 'i' reaches 10 , condition i<10 fails so loop terminates
{
product[i] = first[i] * second[i] //value stored at 'i' index of product = value of 'i' index of first array * value of 'i' index of second array
}
that for loop would be :
product[0]=first[0]*second[0] = 1.2*2.3= ..
product[1]=first[1]*second[1]=1.3*4.2=..
and continues up to product[9]=first[9]*second[9]=....
What you can add:
Declare String before for loop : ex String result=" ";
Inside for loop , style the output for arraays and concat it to the result :
ex, result=result+" "+ first[i]+" * "+second[i]+" =" +product[i] + "\n" ;
// this will collect all your contents of array in one string , ie result
Now you can display result in one line using whatever is required, just display that string "result"