//febonacci
Series Logic Result:0,1,1,2,3,5,8,13,21...
int i, count, f1 = 0, f2 = 1, f3 = 0;
Console.Write("Enter the
Limit : ");
count = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);
for (i = 0; i <= count; i++)
{
f3 = f1 + f2;
Console.WriteLine(f3);
f1 = f2;
f2 = f3;
}
Console.ReadLine();
//Check
Weather Given string is palindrome or not
static void Main(string[] args)
{
string s, revs = "";
Console.WriteLine(" Enter
string");
s = Console.ReadLine();
for (int i = s.Length - 1; i >= 0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) //
Checking whether string is palindrome or not
{
Console.WriteLine("String is
Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is
not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
Console.ReadKey();
}
//PrimeNumber
Logic Result Divided by It self Only
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; 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();
}
//Factorial
of Given Number 5!=5*4*3*2*1
Console.WriteLine("enter n
value");
int num = Convert.ToInt32(Console.ReadLine());
int k = num;
int result = 1;
while (num > 0)
{
result = result * num;
num--;
}
Console.WriteLine("factorial of"+k+" is"+result);
No comments:
Post a Comment