jeudi 23 avril 2015

write a function that square entries of a vector( input vectors should be passed as pointer)

How do I write a function that square entries of a vector( input vectors should be passed as pointer). I couldn't define my vector in function as pointer! What should I do? hi guys..totally a a beginner...

#include <stdio.h>

int squareVec(double vec, int n)
{
  int j = 0;
  for(j = 1, j < dim; --j)
  {
    *vec[j] = &vec[j] * &vec[j];
  }
  return vec;
}

main()
{
  double vec[3] = { -1.0, 2.0, 0.0 };
  int j = 0;
  squareVec(vec, 3);
  for(j = 0; j < 3; ++j)
  {
    printf("vec[%d] = %f ", j, vec[j]);
  }
  printf("\n");
}

Aucun commentaire:

Enregistrer un commentaire