You are close.
svm_problem.l is the number of samples in the database, so in this case it will be 2.
Since libsvm uses a sparse notation, so you need to indicate when each row ends with an index of -1, for instance:
x[0][0].index = 1
x[0][0].value = 1.5
x[0][1].index = 2
x[0][1].value = 2.5
x[0][2].index = 3
x[0][2].value = 4.5
x[0][3].index = -1