hercioneto

Algoritmo 3 de 25-09-18

Sep 25th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public class Program
  12.     {
  13.         public static void recursividadeVetor(int[] vetor, int posicao) {
  14.             if ( posicao == vetor.Length ) {
  15.             return;
  16.             }
  17.             vetor[posicao] = posicao+1;
  18.                      
  19.             //apenas mostrar o vetor
  20.  
  21.             Console.WriteLine("Preencheu a posição {0}",posicao);            
  22.             Console.WriteLine("Vetor preenchido: ");
  23.             for ( int i = 0; i < vetor.Length; ++i ) {
  24.             Console.WriteLine( vetor[ i ] + " ");
  25.             }
  26.             //fim mostrar
  27.            
  28.             recursividadeVetor( vetor , posicao + 1 );
  29.         }
  30.        
  31.        
  32.         public static void Main(string[] args)
  33.         {
  34.             int[] vetor = new int[10 ];
  35.             recursividadeVetor( vetor , 0 );
  36.             Console.WriteLine("Vetor preenchido final: ");
  37.             for ( int i = 0; i < vetor.Length; ++i ) {
  38.             Console.WriteLine( vetor[ i ] + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment