If you want, you can do what you want with BLAS , basic linear algebra routines that are optimized. It is not in the C standard, it is a package that you must install yourself.
Sample code to achieve the desired result:
#include <stdio.h>
The names of the functions are not obvious, but by reading the recommendations, you can begin to guess what the BLAS functions do. sscal() can be divided into s for single precision and scal for scale , which means this function works with floats. The same function for double precision is called dscal() .
If you need to scale a vector with a constant and add it to another, BLAS also got a function:
saxpy() saxpy float a*x + y y[i] += a*x
As you can guess, there is daxpy() , which works on doubles .
source share