Wednesday, 23 April 2014

C# program to find the sum of series 1+3+5+…+100 (adding odd number up to 100)

SOURCE CODE :-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace sumodd
{

    class sum
    {
        public void sumodd()
        {
            int i;
            int sam = 0;
             
        for (i = 0; i <= 100; i++)
          {
      
              if (i%2 != 0)
              {
            int count = 0;
            sam = sam + i;
            count++;
              }
        }
      Console.WriteLine("sum of 1+3+5+...100 is " + sam);
   
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            sum s = new sum();
            s.sumodd();

        }
    }
}

OUTPUT:-

SUM OF 1+3+5+… 100 IS 2500

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016