Tuesday, March 25, 2014

Final Review_24_26 (Message Box)

Ex 24.    Create an array of doubles and  initialize it with the following values:             
-3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9
{

  double[] A = new double [12] { -3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9 };
  double[] B = { -3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9 };

                        for (int i = 0; i < A.Length; i++)
                        {
                            Console.WriteLine("Index: {0}  Value: {1}", i, A[i]);
                        }
                        Console.WriteLine();
                        //Different way to display array in single line.
                        Console.WriteLine(String.Join(", ", B));
}
 //========================Ex 25=======================
Ex 25.    Write a statement to change the fifth element to the new value: 16.9
{
 double[] A = { -3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9 };
 double newValue = 16.9;
                        A[4] = newValue;
                        Console.WriteLine(String.Join(", ", A));
}
//========================Ex 26=======================
Ex 26.    Write a statement to decrease the last element by 3.7

{
double[] A = { -3.5, 2.3, 5.9, -6.9, -12.1, 15.6, 4.7, -3.8, -17.3, -11.4, 12.6, 19.9 };
                        A[A.Length - 1] -= 3.7;
                        Console.WriteLine(String.Join(", ", A));
}

No comments:

Post a Comment