C# Program:To Do Sum Of Even Numbers From Given Array Set

Monday 20 February 2012
using System;
class ArraySum
{
    public static void Main()
    {
        int[] score={1,5,6,2,8,15,13,17,4,12};
        int sum=0;
        for(int i=0;i<=9;i++)
        {
            if(score[i]%2==0)
            {
                sum=sum+score[i];
            }  
        }
        Console.WriteLine("Sum:"+sum);
    }
}

2 comments:

  1. ImRamesh said...:

    Hi Nice post,
    We can also do this
    static long TotalAllEvenInts(int[] intArray) {
    return (from i in intArray where i % 2 == 0 select (long)i).Sum();
    }

  1. Mounika said...:

    It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

Post a Comment