Facebook
From Eduardo, 3 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 120
  1. /*I want conver this code to python
  2.   Write a program in C-C that walks through an array and generates a histogram based on the numbers in the array. The array is named myArray and contains 10 elements that correspond to integers from 1 to 5. A histogram represents that both an element appears in a dataset. For example, for the array: myArray:-(1,2,1,3,3,1,2,1,5,1) the histogram would look like this:
  3.  
  4. 1: *****
  5. 2: **
  6. 3: **
  7. 4:
  8. 5: *
  9.  
  10. */
  11.  
  12. Dim mayorSec As Integer = 1
  13. Dim mayorSecAux As Integer = 1
  14. Dim numeroMayorSec As Integer = 0
  15. Dim numeroAux As Integer = 0
  16. Dim i As Integer = 0
  17. Do While (i < myArray.Length)
  18.     If (myArray(i) = numeroAux) Then
  19.         mayorSecAux = (mayorSecAux + 1)
  20.     Else
  21.         mayorSecAux = 0
  22.     End If
  23.    
  24.     If (mayorSecAux > mayorSec) Then
  25.         mayorSec = mayorSecAux
  26.         numeroMayorSec = myArray(i)
  27.     End If
  28.    
  29.     numeroAux = myArray(i)
  30.     i = (i + 1)
  31. Loop
  32.  
  33. Console.WriteLine(("Longest: "  _
  34.                 + (mayorSec + 1)))
  35. Console.WriteLine(("Number: " + numeroMayorSec))

Replies to Untitled rss

Title Name Language When
Re: Untitled Eduardo csharp 3 Years ago.