Palindrome Number
A Palindrome is a number that remains the same when its digits are reversed, for example 121, 131, 141 and so on.
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- int r = 0;
- int rev = 0;
- int orginal=0;
- Console.WriteLine("Enter a number \n");
- number = sbyte.Parse(Console.ReadLine());
- orginal=number;
- while (number > 0)
- {
- r = number % 10;
- rev = (rev*10) + r;
- number = number / 10;
- }
- if (orginal == rev)
- {
- Console.WriteLine("Palindrome Number ");
- }
- else
- {
- Console.WriteLine("Not Palindrome Number ");
- }
- Console.ReadLine();
- }
- }
Output
Armstrong Number
When the sum of the cubes of the digits of a number is equal to the number itself then the number is an Armstrong number, for example 153 = (1*1*1)+(5*5*5)+(3*3*3).
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- int r = 0;
- int rev = 0;
- int orginal=0;
-
- Console.WriteLine("Enter a number \n");
- number = int.Parse(Console.ReadLine());
- orginal=number;
- while (number > 0)
- {
- r = number % 10;
- rev = rev + (r*r*r);
- number = number / 10;
- }
- if (orginal == rev)
- {
- Console.WriteLine("Armstrong Number ");
- }
- else
- {
- Console.WriteLine("Not Armstrong Number ");
- }
-
- Console.ReadLine();
- }
- }
Output
Perfect Number
A Perfect Number is a positive integer equal to the sum of its proper positive divisors except on the divisor.
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- int r = 0;
- int rev = 0;
- int orginal=0;
- int s = 0;
- Console.WriteLine("Enter a number \n");
- number = int.Parse(Console.ReadLine());
- orginal=number;
- for (int i = 1; i < number; i++)
- {
- if (number%i==0)
- {
- s = s + i;
- }
- }
- if (number == s)
- {
- Console.WriteLine("Perfect Number ");
- }
- else
- {
- Console.WriteLine("Not Perfect Number ");
- }
-
- Console.ReadLine();
- }
- }
Output
Fibonacci Series
The Fibonacci series is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21….N that is the sum of the previous two numbers.
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- int n1 = 0,n2=1,fib=0;
-
- Console.WriteLine("Enter a number \n");
- number = int.Parse(Console.ReadLine());
- Console.Write(n1);
- Console.Write(" ");
- Console.Write(n2);
- Console.Write(" ");
- for (int i = 0; i <= number; i++)
- {
- fib = n1 + n2;
- Console.Write(fib);
- Console.Write(" ");
- n1 = n2;
- n2 = fib;
- }
-
- Console.ReadLine();
- }
- }
Output
Print a pattern
*
**
***
****
- class Program
- {
- static void Main(string[] args)
- {
-
-
-
-
-
- for (int i = 0; i <= 4; i++)
- {
- for (int j = 0; j <= i; j++)
- {
- Console.Write("*");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Output
Print a pattern
****
***
**
*
- class Program
- {
- static void Main(string[] args)
- {
-
-
-
-
-
- for (int i = 4; i>=0; i--)
- {
- for (int j = i; j>=0 ; j--)
- {
- Console.Write("*");
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Output