class Program { static void Main(string[] args) { int a = 10, b = 5; if (b > 0) { while (b > 0) { a++; b--; } } // when 'b' is negative if (b < 0) { while (b < 0) { a--; b++; } } Console.Write("Sum is: " + a); } }
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts
Monday, June 21, 2021
Find sum of two number without using any arithmetic operator.
Sunday, September 15, 2019
List array removed and append the last in c#
class Program
{
static void Main(string[] args)
{
List<string> list1 = new List<string>();
// list elements
list1.Add("A");
list1.Add("I");
list1.Add("G");
list1.Add("B");
list1.Add("E");
list1.Add("H");
list1.Add("F");
list1.Add("C");
list1.Add("D");
list1.Add("a");
list1.Add("--Geen--");
Console.WriteLine("Original List");
List<string> list2 = new List<string>();
for (int i = 0; i < list1.Count; i++)
{
if (list1[i].Contains("--Geen--"))
{
list2.Add(list1[i]);
list1.RemoveAt(i);
}
}
list1.Add(list2[0]);
Console.WriteLine("\nSorted List");
// use of List.Sort() method
list1.Sort(StringComparer.Ordinal);
}
}
Subscribe to:
Posts (Atom)