Hello,
Hope you are doing well.
there is a bit problem in your algorithm you are using a 'number' as an integer to get data from a user and using the same variable inside the while loop makes it value 0,
that's why it says
Sum of the digits 0 is 36
and this is the reason the for loop is not executing because of the number=0.
Solution is simple
take another variable save the original value in it and that's it.
int number,val;
int sum = 0;
Console.WriteLine("Enter a number with at most 7 digits: ");
number = Convert.ToInt32(Console.ReadLine());
val = number;
while (number != 0)
{
sum += number % 10;
number /= 10;
}
Console.WriteLine("Sum of the digits of " + val + " is " + sum);
for (int i = 1; i <= val; i++)
{
if (val % i == 0)
{
Console.WriteLine("The divisors of " + sum + " are " + i.ToString());
}
}
Console.ReadLine();