P16 To find the square of first N numbers and to calculate its sum



    class Program
    {
        static void Main(string[] args)
        {
            int n, s, sum = 0;
            Console.Write("Enter the limit : ");
            n = int.Parse(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                s = i * i;
                sum = sum + s;
                Console.WriteLine("Square of " + i + " is " + s);
            }
            Console.WriteLine("Sum of the squares is " + sum);
            Console.ReadLine();
        }
    }

Output : 



No comments:

Post a Comment