/*   This program sums the terms of the infinite series
     whose ith term is 1/i^2, into three different sums, 
     sum_k = sum(1/l^2), l=k(mod 3), k=0,1,2, where l<=n.
*/

#include <stdio.h>

main()
{
   int i, n, resp;
   float sum_one, sum_two, sum_three;

   do {
      printf( "\nAgain (1 = yes, 0 = no)? " );
      scanf( "%d", &resp );
      if ( resp ) {
         printf( "n = ? " );
         scanf( "%d", &n );
         for ( i = n, sum_one = sum_two = sum_three = 0.0; i > 0; i-- )
	   switch ( i % 3 ) {
	   case 0:
	     sum_one += 1 / ( ( float ) i * ( float ) i );
	     break;
	   case 1:
	     sum_two +=  1 / ( ( float ) i * ( float ) i );
	     break;
	   case 2:
	     sum_three += 1 / ( ( float ) i * ( float ) i );
	     break;
	   }
         printf( "Sum of 1st terms = %f\n", sum_one );
	 printf( "Sum of 2nd terms = %f\n", sum_two );
	 printf( "Sum of 3rd terms = %f\n", sum_three );
      }
   } while ( resp );
}

