Sunday 27 January 2013


//Write a program to take as input a number n and find the sum of all numbers from 1 to n.
//Eg. If input is 6 then output should be 1+2+3+4+5+6 = 21 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace addtwonos
{
    class Program
    {
       
        static void Main(string[] args)
        {
            int n = 0, total = 0, temp = 0;
            Console.Write("Enter the n number :  ");
            n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                Console.Write("Enter the {0} number ", i);
                temp = int.Parse(Console.ReadLine());

                total = total + temp;
            }

            Console.WriteLine("The total of a number u entered is : " + total);
            //total = Int32.Parse(Console.ReadLine());
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment