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

Título: C# programa que pide al usuario n números y calcula el sumatorio de esas cifras
Publicado por: César Krall en 24 de Julio 2016, 19:38
Ejercicio resuelto en C# (publicado por Dimitar Stefanov):

Citar
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:

Código: [Seleccionar]
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);
}
}
}