//print 1 to 100 numbers
PrintNumbers(1);
void PrintNumbers(int n)
{
if (n <= 100)
{
Console.WriteLine(n);
PrintNumbers(n + 1);
}
}
//---------------------------------------------------------------------------------------------
//sorting array
int[] arr = new int[] { 1, 9, 6, 7, 5, 9 };
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] < arr[j])
{
int temp;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
foreach (int value in arr)
{
Console.WriteLine(value);
}
//---------------------------------------------------------------------------------------------
//print reverse number
int number = 1234;
int reverse = 0;
while (number > 0)
{
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number / 10;
}
Console.WriteLine(reverse);
//---------------------------------------------------------------------------------
//print reverse string
string givenString = "Rajesh";
string reverseString = "";
int length = givenString.Length - 1;
while (length >= 0)
{
reverseString = reverseString + givenString[length];
length--;
}
Console.WriteLine("Reverse word is ", reverseString);
//---------------------------------------------------------------------
//print buplicates string
//string[] arr = { "a", "d", "a", "b", "c", "d", "e", "d" };
//print buplicates
int[] arr = { 2, 2, 3, 4, 4, 5, 6, 6 };
for (int i = 0; i < arr.Length; i++)
{
for (int j = i; j < arr.Length; j++)
{
if (arr[i] == arr[j] && i != j)
{
Console.WriteLine(arr[i]);
break;
}
}
}
//-------------------------------------------------------------------
int total = getsum(999);
Console.WriteLine("sum of number is : " + getsum(total));
int getsum(int number)
{
int sum = 0;
while (number > 0)
{
int rem = number % 10;
sum = sum + rem;
number = number / 10;
}
return sum;
}
//-------------------------------------------------------------------
string str = "Raama";
var result = str.GroupBy(c => c)
.Select(c => new { Char = c.Key, Count = c.Count() });
foreach (var item in result)
{
Console.WriteLine(item);
}
//-------------------------------------------------------------------
//remove duplicates
int[] numbers = { 1, 2, 2, 3, 4, 4, 5 };
int[] uniqueNumbers = numbers.Distinct().ToArray();
foreach (var item in uniqueNumbers)
{
Console.WriteLine(item);
}
//--------------------------------------------------------------------------
//factorial of 5
int factorial = 1;
for (int num = 5; num > 0; num--)
{
factorial = factorial * num;
}
Console.WriteLine("Factorial of {0} is {1}", 5, factorial);
//-----with recursion
int factorial(int num){
int result = 1;
if (num>0)
{
result = result * num;
factorial(num -1);
}
return result;
}
Console.WriteLine(factorial(1));
int[] arr = { 1, 2, 3, 4, 4, 5, 6, 6, 7 };
// Create a new array to store unique elements
int[] uniqueArr = new int[arr.Length];
int k = 0;
// Traverse through the array
for (int i = 0; i < arr.Length; i++)
{
bool isDuplicate = false;
// Check if current element is a duplicate
for (int j = 0; j < k; j++)
{
if (arr[i] == uniqueArr[j])
{
isDuplicate = true;
break;
}
}
// Add the element to the unique array if it's not a duplicate
if (!isDuplicate)
{
uniqueArr[k] = arr[i];
k++;
}
}
// Print the unique elements in the array
for (int i = 0; i < k; i++)
{
Console.Write(uniqueArr[i] + " ");
}
[22/03, 12:50 pm] Rajesh: SELECT MAX(Salary) as SecondHighestSalary
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees);
[22/03, 12:51 pm] Rajesh: SELECT TOP 1 SALARY
SELECT TOP 1 EmpId , EmpName
FROM (
SELECT DISTINCT TOP 2 EmpId , EmpName
FROM tbl_Employee
ORDER BY EmpId DESC
) tbl_Employee order by EmpId
Comments
Post a Comment