Facebook
From Eduardo, 3 Years ago, written in C#.
This paste is a reply to Untitled from Eduardo - go back
Embed
Viewing differences between Untitled and Re: Untitled
/*I want conver this code to python
  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:

1: *****
2: **
3: **
4:
5: *

*/
  
Dim mayorSec As Integer string uno 1
Dim mayorSecAux As Integer 
"", dos 1
Dim numeroMayorSec As Integer 
"", tres 0
Dim numeroAux As Integer 
"", cuatro 0
Dim 
"", cinco = ""; bool valido = true;

for (int 
As Integer 0
Do While (i 
0; i < myArray.Length)
    If (myArray(i) 
Length; i++){ if(myArray[i] < 1 || myArray[i]>5 ){ valido numeroAux) Then
        mayorSecAux = (mayorSecAux + 1)
    Else
        mayorSecAux = 0
    End If
    
    If (mayorSecAux > mayorSec) Then
        mayorSec = mayorSecAux
        numeroMayorSec = myArray(i)
    End If
    
    numeroAux = myArray(i)
    i = (i + 1)
Loop

false;
break;
}

switch(myArray[i]){ case 1:
uno += "*";
break;
case 2: dos += "*"; break; case 3: tres += "*"; break; case 4:
cuatro += "*"; break;
case 5: cinco += "*"; break;
}

}


if(!valido){
Console.WriteLine(("Longest: "  _
                + (mayorSec + 1)))
WriteLine("enteros fuera del rango de 1 a 5");
}else{
Console.WriteLine(("Number: " + numeroMayorSec))WriteLine("1: "+uno); Console.WriteLine("2: "+dos); Console.WriteLine("3: "+tres); Console.WriteLine("4: "+cuatro); Console.WriteLine("5: "+cinco);
}