using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class SumOfDigits
{
static void Main(string[] args)
{
int num, sum = 0, res;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
res = num % 10;
num = num / 10;
sum = sum + res;
}
Console.WriteLine("Sum of Digits of the Number : "+sum);
Console.ReadLine();
}
}
}
---------------------------
OUTPUT
Enter a Number : 234
Sum of Digits of the Number : 9
--------------
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class SumOfDigits
{
static void Main(string[] args)
{
int num, sum = 0, res;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
res = num % 10;
num = num / 10;
sum = sum + res;
}
Console.WriteLine("Sum of Digits of the Number : "+sum);
Console.ReadLine();
}
}
}
---------------------------
OUTPUT
Enter a Number : 234
Sum of Digits of the Number : 9
--------------
this blog good for us. thanks and keep it.
ReplyDelete