Advertisement
Fhernd

Pruebaparams.cs

Nov 10th, 2017
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. class Pruebaparams
  2. {
  3.     static int Suma(params int[] operandos)
  4.     {
  5.         int suma = 0;
  6.         for (int i = 0; i < operandos.Length; i++)
  7.         {
  8.             suma += operandos[i];                   // acumulador de los operandos
  9.         }
  10.  
  11.         return suma;
  12.     }
  13.  
  14.     static void Main()
  15.     {
  16.         int total = Suma(1, 2, 3, 4, 5);
  17.         Console.WriteLine(total);                   // 15
  18.         total = Suma(11, 19, 29);
  19.         Console.WriteLine(total);                   // 59
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement