You are on page 1of 6

change values of two numbers:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
int first = 100;
int second = 200;
first = first + second;
second = first - second;
first = first - second;
Console.WriteLine(first);
Console.WriteLine(second);
}
}
}

factorial:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your number");
int value = int.Parse(Console.ReadLine());
Console.WriteLine($"Factorial of number {value} is
{Factorial(value)}");
}
public static int Factorial(int value)
{
if (value <= 0)
{
return 1;
}
return value * Factorial(value - 1);
}
}
}

fibonachi:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your number");
int value = int.Parse(Console.ReadLine());
Fibonachi(value);
}
public static void Fibonachi(int value)
{
int a = 0;
int b = 1;
int c = 0;
Console.WriteLine("Members of fibonachi array are: ");
Console.WriteLine(a);
Console.WriteLine(b);
for (int i = 2; i < value; i++)
{
c = a + b;
Console.WriteLine(c);
a = b;
b = c;
}
}
}
}

Division by remainder:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter first value: ");
int value1 = int.Parse(Console.ReadLine());

Console.WriteLine("Enter second value: ");


int value2 = int.Parse(Console.ReadLine());

DividerRemainder(value1, value2);
}
public static void DividerRemainder(int val1, int val2)
{
if (val2 == 0)
{
Console.WriteLine("Values cannot be zero.");
}
else if (val2 > val1)
{
Console.WriteLine("Second value cannot be higher than first one.");
}
else
{
Console.WriteLine(val1%val2);
}
}
}
}

armstrong number:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
int number, remainder, sum = 0;
Console.Write("enter the Number");
number = int.Parse(Console.ReadLine());
for (int i = number; i > 0; i = i / 10)
{
remainder = i % 10;
sum = sum + remainder * remainder * remainder;

}
if (sum == number)
{
Console.Write("Entered Number is an Armstrong Number");
}
else
Console.Write("Entered Number is not an Armstrong Number");
Console.ReadLine();
}
}
}

prime number:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
public static void Main()
{
Console.Write("Enter a Number : ");
int num;
num = Convert.ToInt32(Console.ReadLine());
int k;
k = 0;
for (int i = 1; i <= num / 2; i++)
{
if (num % i == 0)
{
k++;
}
}
if (k == 2)
{
Console.WriteLine("Entered Number is a Prime Number and the Largest
Factor is {0}", num);
}
else
{
Console.WriteLine("Not a Prime Number");
}
Console.ReadLine();
}
}
}

int pallindrom:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
public static void Main()
{
Console.WriteLine("Enter your number: ");
int value = int.Parse(Console.ReadLine());

PallindromValue(value);
}
public static void PallindromValue(int value)
{
string valueToString = value.ToString();
string result = null;
string itIs = "This value is pallindrom!";
string itNotIs = "This value is NOT pallindrom!";

for (int i = valueToString.Length - 1; i >= 0; i--)


{
result = result + valueToString[i];
}
if (int.Parse(valueToString) == int.Parse(result))
{
Console.WriteLine(itIs);
}
else
{
Console.WriteLine(itNotIs);
}
}
}
}
Devision by 2 == 0(%):

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
public static void Main()
{
Console.WriteLine("Please provide a value: ");
int value = int.Parse(Console.ReadLine());

ValueDevision(value);
}
public static void ValueDevision(int val)
{
if (val % 2 == 0)
{
Console.WriteLine("Number you provided can be devided by 2!");
}
else
{
Console.WriteLine("Wrong number!");
}
}
}
}

factor of the entered number:

using System;
using System.Linq;

namespace Algorythams
{
class Program
{
public static void Main()
{
Console.WriteLine("Please provide a value: ");
int value = int.Parse(Console.ReadLine());

FactorValue(value);
}
public static void FactorValue(int val)
{
for (int i = 1; i <= val; i++)
{
if (val % i == 0)
{
Console.WriteLine($"This is factor for provided value: {i}");
}
}
}
}
}

You might also like