Opteronic

cs sto 001 Rec Sum of Array Elements

May 15th, 2021
906
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class A
  7. {
  8.     public static int sum = 0;
  9.     public static int[] arrC = { 3, 5, 7, 9 };
  10.  
  11.     public static void RecUp(int n)
  12.     {  
  13.         if (n == arrC.Length)
  14.         {
  15.             Console.WriteLine($"The sum of array elements is {sum}");
  16.             return;
  17.         }
  18.  
  19.         int num = arrC[n];
  20.         sum = sum + num;
  21.  
  22.         RecUp(n + 1);
  23.     }
  24.  
  25.     public static void F1()
  26.     {      
  27.         RecUp(0);
  28.            
  29.         Console.ReadKey();
  30.     }
  31.     public static void Main() { F1(); }
  32. }
  33.  
RAW Paste Data