Add 1.0/1.0+1.0/2.0+... when you do integer division (e.g., 1/2) regardless of the variable the result is going into it still still gets truncated. If you haven't already make sure your result is declared as type double otherwise nothing will work.
sum = sum +i(1.0\i); That's you're killer. First of all, use the correct division symbol: /
Secondly, why is there an 'i' in front of the division?
That statement, corrected, should be:
sum = sum + ( 1.0 / i );
But in the loop's first iteration, you add 1.0 / 0, which is...um....not defined mathematically. In actuality, you get a really huge result.
It didn't work because u are making sum zero in each iteration of the loop .. so just remove sum=0 from the loop.. it's enough to initialize it before the loop.
for (i = 0; i <= 10; i++)
sum = sum +i(1.0\i);
While I agree it looks better to initialize sum outside the loop, it is NOT being reset to 0 each iteration, any more than counter i is. The initialization statement is executed only once.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...