Facebook
From Eduardo, 3 Years ago, written in C#.
This paste is a reply to Untitled from Eduardo - view diff
Embed
Download Paste or View Raw
Hits: 125
  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. string uno = "", dos = "", tres = "", cuatro = "", cinco = ""; bool valido = true;
  13.  
  14. for (int i = 0; i < myArray.Length; i++){ if(myArray[i] < 1 || myArray[i]>5 ){ valido = false;
  15. break;
  16. }
  17.  
  18. switch(myArray[i]){ case 1:
  19. uno += "*";
  20. break;
  21. case 2: dos += "*"; break; case 3: tres += "*"; break; case 4:
  22. cuatro += "*"; break;
  23. case 5: cinco += "*"; break;
  24. }
  25.  
  26. }
  27.  
  28.  
  29. if(!valido){
  30. Console.WriteLine("enteros fuera del rango de 1 a 5");
  31. }else{
  32. Console.WriteLine("1: "+uno); Console.WriteLine("2: "+dos); Console.WriteLine("3: "+tres); Console.WriteLine("4: "+cuatro); Console.WriteLine("5: "+cinco);
  33. }
  34.