bhalash

Project Euler problem #6 solution.

Jun 2nd, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.32 KB | None | 0 0
  1. using System;
  2.  
  3. public class Six
  4. {
  5.     static void Main()
  6.     {
  7.         double a = 100;
  8.         double b = 0;
  9.         double c = 0;
  10.        
  11.         for (int i = 1; i <= a; i++)
  12.         {
  13.             b += (i * i);
  14.             c += i;
  15.         }
  16.  
  17.         c = c * c;
  18.  
  19.         if (b > c)
  20.             Console.WriteLine("\n{0}\n", b - c);
  21.         else if (c > b)
  22.             Console.WriteLine("\n{0}\n", c - b);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment