Applications in C# Programming Language

Topics: Integer, Real number, Natural number Pages: 3 (351 words) Published: April 16, 2012
a) Write an application that reads a non-negative integer from an input dialogue and computes and prints its factorial

static void Main(string[] args)
{
int i, n, fac = 1;
string s;
Console.WriteLine("Please enter any number to find its factorial(0 to 19):\n"); s = Console.ReadLine();
n = Int32.Parse(s);
for (i = 1; i <= n; i++)
{
fac = fac * i;
}
Console.WriteLine("\nThe factorial of '{0}' is {1}.", n, fac); Console.Read();
}
}
}

b) A palindrome is a number or text phrase that reads the same backwards as forwards e.g each of the following five-digit integers are palindromes 12321; 55555; 45554; 11611. Write an application that reads in a five-digit integer and determine whether it is a palindrome.

static void Main(string[] args)
{
Console.Write(" Enter any number: ");
int num = int.Parse(Console.ReadLine());
int rev = 0, n, rem;
n = num;
while (num != 0)
{
rem = num % 10;
rev = rev * 10 + rem;
num = num / 10;
}
Console.WriteLine(" \n Original number is " + n); Console.WriteLine(" \n Reversed number is " + rev); if (n == rev)
{
Console.WriteLine("\n Original number = Reversed number."); Console.WriteLine("\n So, {0} is a Palindrome ", n); Console.ReadLine();
}
else
{
Console.WriteLine("\n Original number != Reversed number."); Console.WriteLine("\n So, {0} is not a Palindrome ", n); Console.ReadLine();
}
}
}
}

c) An application to determine whether any of several department store customers has exceeded their credit...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Programming Language Essay
  • Programming in C# Essay
  • C++ Programming Language Essay
  • Essay about Programming C++
  • programming C Essay
  • Introduction to the C# Programming Language Essay
  • Programming Language Essay
  • Programming Languages Essay

Become a StudyMode Member

Sign Up - It's Free