0
To find sum of n numbers in c#
2 Réponses
+ 9
/*
* C# Program to Generate the Sum of N Numbers
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program
{
class Program
{
static void Main(string[] args)
{
int i, sum = 0,n;
Console.Write("Enter no of terms : ");
n = int.Parse(Console.ReadLine());
for (i = 0; i <= n; i++)
{
sum = sum + i;
}
Console.WriteLine("\nSum of N Numbers : " + sum);
Console.ReadLine();
}
}
}
0
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the number");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i <n; i++)
{
int sum=sum + i;
}
Console.WriteLine("the sum of the number is :"+sum);
Console.ReadKey();
}
}
}
// error: (the sum does not exist In the current context)
help me plzz