Foros aprenderaprogramar.com
Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: César Krall en 24 de Julio 2016, 19:38
-
Ejercicio resuelto en C# (publicado por Dimitar Stefanov):
Sum of N Numbers
Description
Write a program that enters a number N and after that enters more N numbers and calculates and prints their sum.
Note: You may need to use a for-loop.
El código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SumOfNNumbers {
class Program {
static void Main() {
int cantidad = int.Parse(Console.ReadLine());
double result=0.0d;
for(int i = 0;i<cantidad;i++) {
result = result + double.Parse(Console.ReadLine());
}
Console.WriteLine(result);
}
}
}