Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ContaPagine
- {
- class Program
- {
- static void Main(string[] args)
- {
- int NUM_MIN = 1, NUM_MAX = 708, STUD = 26;
- int[] contatore = new int[NUM_MAX - NUM_MIN];
- for (int i = NUM_MIN; i <= NUM_MAX; i++)
- {
- if (i <= STUD)
- contatore[i - NUM_MIN]++;
- else
- {
- int val = SommaCifre(i);
- while (val > STUD) val = SommaCifre(val);
- contatore[val - 1]++;
- }
- }
- for(int i = NUM_MIN; i < NUM_MAX; i++)
- {
- if (contatore[i - NUM_MIN] != 0)
- {
- Console.WriteLine("{0} :\t{1:0.000}", i - NUM_MIN + 1, (double)contatore[i - NUM_MIN] * 100 / (NUM_MAX - NUM_MIN));
- }
- }
- Console.ReadKey();
- }
- static int SommaCifre(int n)
- {
- int s = 0;
- foreach (char c in n.ToString().ToCharArray()) s += Convert.ToInt16(c.ToString());
- return s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement