Write a program that calculate the sum of the ff. quantities. In each case, N indicates a quantity specified by user. A. 1+½+⅓+¼...+¹/N=_____ B. 1²+2²+3²+... N²=______

Write a program that calculate the sum of the ff. quantities. In each case, N indicates a quantity specified by user.
A. 1+½+⅓+¼...+¹/N=_____
B. 1²+2²+3²+... N²=______

Solution: 
#include < stdio.h >
#include < conio.h >

void main()
{
      int N = 1, i;
      float sumA = 0.0;
clrscr();
printf("Limit : ");
scanf("%d", &N);

for (i = 1; i < = N; i++)
{
sumA = sumA + (1/(float)i); 
}
printf("Sum : %.3f\n", sumA);
getch();
}


No comments