memset(a, n*n, n*sizeof(int));
This is probably not doing what you expect. The doc says that the value param is converted to an unsigned char. Each byte will be set to that value. When you look at the 4 or 8 bytes that comprise an int, you'll get junk. The only useful value I've seen passed in is 0. That will work to init a double as well
The only way to initialize an array of numerics to a known value, like 42, is to write a loop