Advertisement
Guest User

Exercicio 5

a guest
Nov 29th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. static System.Boolean IsNumeric(System.Object Expression)
  2. {
  3. if (Expression == null || Expression is DateTime)
  4. return false;
  5.  
  6. if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
  7. return true;
  8.  
  9. try
  10. {
  11. if (Expression is string)
  12. Double.Parse(Expression as string);
  13. else
  14. Double.Parse(Expression.ToString());
  15. return true;
  16. }
  17. catch { } // just dismiss errors but return false
  18. return false;
  19. }
  20.  
  21. static void Main(string[] args)
  22. {
  23. int[] vetor = new int[16];
  24.  
  25. for(int i = 0; i < vetor.Count(); i++)
  26. {
  27. debugKey:
  28. Console.Write("Digite o " + (i + 1) + "º número: ");
  29. string n = Console.ReadLine();
  30. if (IsNumeric(n))
  31. {
  32. vetor[i]= int.Parse(n);
  33. Console.WriteLine("");
  34. }
  35. else
  36. {
  37. Console.WriteLine("");
  38. Console.WriteLine("Error: Valor invalido!");
  39. Console.WriteLine("");
  40. goto debugKey;
  41. }
  42. }
  43.  
  44. // Copiar valores a outro array
  45. int[] vetor2 = new int[vetor.Count()];
  46. for (int i = 0; i < vetor2.Count(); i++)
  47. {
  48. vetor2[i] = vetor[i];
  49. }
  50.  
  51.  
  52. // Inverter Valores
  53. for (int i = 0; i < 8; i++)
  54. {
  55. vetor[i] = vetor2[15 - i];
  56. vetor[15 - i] = vetor2[i];
  57. }
  58.  
  59. Console.WriteLine("");
  60. Console.WriteLine("Valores dos Vetores");
  61. for (int i = 0; i < vetor.Count(); i++)
  62. {
  63. Console.WriteLine("Vetor nº" + (i + 1) +": " + vetor[i]);
  64. }
  65.  
  66. Console.Read();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement