-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask10.cs
More file actions
37 lines (22 loc) · 957 Bytes
/
task10.cs
File metadata and controls
37 lines (22 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace functions_and_methods
{
class Program
{
public static void Main() {
int number;
Console.Write("\n\nFunction : To calculate the sum of the individual digits of a number :\n");
Console.Write("-------------------------------------------\n");
Console.Write("Enter a number: ");
number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The sume of the digits of the number {0} is : {1} \n",number,SumCal(number));
}
public static int SumCal(int n) {
string number1 = Convert.ToString(n);
int sum = 0;
for (int i = 0; i < number1.Length; i++)
sum += Convert.ToInt32(number1.Substring(i,1));
return sum;
}
}
}