sum of number in c#
Sum of number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Programone
{
class Program
{
static void Main(string[] args)
{
int num1, sum=0, temp;
Console.WriteLine("Enter number");
num1 = int.Parse(Console.ReadLine());
while (num1 != 0)
{
temp = num1 % 10;
num1 = num1 / 10;
sum = sum + temp;
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
}
reverse of number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Programone
{
class Program
{
static void Main(string[] args)
{
int num1, sum=0, temp;
Console.WriteLine("Enter number");
num1 = int.Parse(Console.ReadLine());
while (num1 != 0)
{
temp = num1 % 10;
num1 = num1 / 10;
sum = sum + temp;
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
}
reverse of number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Programone
{
class Program
{
static void Main(string[] args)
{
int num1, Rev=0;
Console.WriteLine("Enter number");
num1 = int.Parse(Console.ReadLine());
while (num1 != 0)
{
Rev = Rev * 10;
Rev = Rev+num1 %10;
num1 = num1 / 10;
}
Console.WriteLine(Rev);
Console.ReadLine();
}
}
}
Comments