Tuesday, 27 November 2012

Sum of N Numbers

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

namespace sumof_n_numbers
{
class sumofn
{
static void Main(string[] args)
{
int n, i,sum=0;
int[] a = new int[30];
Console.WriteLine("\tSUM OF N NUMBERS");
Console.WriteLine("\t****************");
Console.WriteLine("Enter How Many Numbers To Count");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements One by one");
for (i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (i = 0; i < n; i++)
{
sum = sum + a[i];
}
Console.WriteLine("The Sum of {0} Number is={1}", n, sum);


}
}
}

No comments:

Post a Comment