static bool isPalindrome(string word) { string rword = ""; foreach (var c in word) rword = c + rword; return rword.ToUpper() == word.ToUpper() ? true : false ; }
The Code Crunchers
Welcome Coders!
ads
Sunday, March 11, 2018
Palindrome Checker C#
Monday, September 23, 2013
Saturday, January 16, 2010
My Fizz Buzz Solution
My Fizz Buzz Solution
Solution 1: Using Ternary Operator
Solution 2: Using IF Operator
Solution 1: Using Ternary Operator
for (int i = 1; i < 101; i++)
{
string result = "";
result = i % 3 == 0 ? "Fizz" : ""; // check if i is divisible by 3
result += i % 5 == 0 ? "Buzz" : "";// check if i is divisible by 5
Console.Write("\n" + i.ToString() + " - " + result);
}
{
string result = "";
result = i % 3 == 0 ? "Fizz" : ""; // check if i is divisible by 3
result += i % 5 == 0 ? "Buzz" : "";// check if i is divisible by 5
Console.Write("\n" + i.ToString() + " - " + result);
}
Solution 2: Using IF Operator
for (int i = 1; i < 101; i++)
{
string result = "";
if (i % 3 == 0) // check if i is divisible by 3
{
//give result the value fizz
result = "Fizz";
}
if (i % 5 == 0) // check if i is divisible by 5
{
//gets the value of result and add to the buzz value giving an output of fizz or fizzbuzz
result += "Buzz";
}
//show result;
Console.Write(" \n" + i.ToString() + " - " + result);
}
{
string result = "";
if (i % 3 == 0) // check if i is divisible by 3
{
//give result the value fizz
result = "Fizz";
}
if (i % 5 == 0) // check if i is divisible by 5
{
//gets the value of result and add to the buzz value giving an output of fizz or fizzbuzz
result += "Buzz";
}
//show result;
Console.Write(" \n" + i.ToString() + " - " + result);
}
Sunday, July 19, 2009
Fabonacci Function c#
|
|
Subscribe to:
Posts (Atom)