fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int **x; //You should probably invest in a better name :P
  6. int lines;
  7. int numbers;
  8.  
  9. std::cout << "How many lines of numbers? ";
  10. std::cin >> lines;
  11.  
  12. x = new int *[lines];
  13.  
  14. for( int i = 0; i < lines; ++i )
  15. {
  16. std::cout << "How many numbers is this line? ";
  17. std::cin >> numbers;
  18. x[i] = new int[numbers];
  19. std::cout << "Please enter the numbers separated by spaces: ";
  20. for( int j = 0; j < numbers; ++j )
  21. {
  22. std::cin >> x[i][j];
  23. }
  24. }
  25.  
  26. std::cout << std::endl << x[1][0] << std::endl;
  27. //
  28. for( int i = 0; i < lines; ++i )
  29. delete[] x[i];
  30.  
  31. delete[] x;
  32. }
Success #stdin #stdout 0s 3432KB
stdin
2
3
1 2 9
3
5 4 3
stdout
How many lines of numbers? How many numbers is this line? Please enter the numbers separated by spaces: How many numbers is this line? Please enter the numbers separated by spaces: 
5