Advertisement
Guest User

contapagine

a guest
Oct 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ContaPagine
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int NUM_MIN = 1, NUM_MAX = 708, STUD = 26;
  14. int[] contatore = new int[NUM_MAX - NUM_MIN];
  15. for (int i = NUM_MIN; i <= NUM_MAX; i++)
  16. {
  17. if (i <= STUD)
  18. contatore[i - NUM_MIN]++;
  19. else
  20. {
  21. int val = SommaCifre(i);
  22. while (val > STUD) val = SommaCifre(val);
  23. contatore[val - 1]++;
  24. }
  25. }
  26. for(int i = NUM_MIN; i < NUM_MAX; i++)
  27. {
  28. if (contatore[i - NUM_MIN] != 0)
  29. {
  30. Console.WriteLine("{0} :\t{1:0.000}", i - NUM_MIN + 1, (double)contatore[i - NUM_MIN] * 100 / (NUM_MAX - NUM_MIN));
  31. }
  32. }
  33. Console.ReadKey();
  34. }
  35. static int SommaCifre(int n)
  36. {
  37. int s = 0;
  38. foreach (char c in n.ToString().ToCharArray()) s += Convert.ToInt16(c.ToString());
  39. return s;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement