articles_code / c_scientific_article / array_dynamic.cc

/*array_blitz.cc*/

/* Dynamic Array objects using Blitz++*/

#include <blitz/array.h>

using namespace blitz;

int main()
{
  int n;

 
  cout << ">>>> Dynamic 1-D Array Demonstration >>>>" << endl << endl;

  Array<float,1> a;
  cout << "Enter the number of elements:: ";
  cin >> n;

  /* Resize the array */
  a.resize(n);

  /* Input the array*/
  for(int i=0;i<n;i++)
    cin >> a(i); /* uses the  () operator to refer each element*/
  
  cout << "a = " << a <<endl << endl;


  cout << ">>>> Dynamic 2-D Array Demonstration >>>>" << endl << endl;

  Array<float,2> A;
  cout << "Enter the number of elements in the two dimensions:: ";
  int r,c;
  cin >> r >> c;

  /* Resize the matrix */
  A.resize(r,c);

  /* Input the array*/
  for(int i=0;i<r;i++)
    {
      for(int j=0;j<c;j++)
	cin >> A(i,j); /* uses the  () operator to refer each element*/
    }
  
  cout << "A = " << A <<endl << endl;


  return 0;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.