Search This Blog

Sunday, 11 February 2018

TH11 Vs TH11 - 3 Star Attack Strategy (Loons, Lava Hound, Minions, Rage ...

Tuesday, 9 June 2015

A program to find whether a given number is prime or not using c#

using System;
class Program
{
static void Main(string[]args)
{
int i;
Console.WriteLine("enter any number");
int a = int.Parse(Console.ReadLine());
for(i=2;i<a;i++)
{
  if(a%i==0)
  break;
}
if(a==1||i==a)
Console.WriteLine("the number is prime");
else
Console.WriteLine("the number is not pirme");
Console.Read(); 
}
}


OUTPUT



CLICK TO DOWNLOAD




A program to find factorial of a number using functions in c#

class Program
        {
            static int Factorial(int n)
            {
                if (n <= 1)
                    return 1;
                int fact = 1;
                for (int i = 2; i <= n; i++)
                {
                    fact = fact * i;
                }
                return fact;
            }
            static void Main(string[] args)
            {
                Console.Write("Enter a Number to find factorial: ");
                int n = Convert.ToInt32(Console.ReadLine());
                int r = Factorial(n);
                Console.WriteLine(n.ToString() + "! = " + r.ToString());
                Console.ReadLine();
            }
        }
    }

OUTPUT


CLICK TO DOWNLOAD

A program to display the astrick pattern as given below

using System;
    class Class2
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 0; i <6; i++)
            {
                for (j = 5; j > i; j--)
                {
                    Console.Write("");
                }
                for (int k = 0; k < i; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }


OUTPUT

CLICK TO DOWNLOAD

 

A program to check whether a given number is Armstrong or not

using System;
    class Class1
    {
        static void Main(string[] args)
        {
            int a, n, i, m = 0;
            Console.WriteLine("Enter any number");
            a = int.Parse(Console.ReadLine());
            n = a;
            for (i = 0; n > 0; i++)
            {
                int x = n % 10;
                m = x * x * x;
                n = n / 10;
            }
            if (a == m)
                Console.WriteLine("the given number is an armstrong number");
            else
                Console.WriteLine("the given number is not armstrong number");
            Console.ReadLine();
        }
    }




OUTPUT

CLICK TO DOWNLOAD