Reverse a string without any use of predefined function
- public static void Main()
- {
- int n = 0;
- Console.WriteLine("Enter a string");
- string s = Console.ReadLine();
- string rev = "";
- foreach (char c in s)
- {
- n++;
- }
- while (n > 0)
- {
- rev = rev + s[n - 1];
- n = n - 1;
- }
- Console.WriteLine(rev);
- Console.ReadKey();
-
- }
Output
Find out Second smallest number
- int[] n = new int[5];
- Console.WriteLine("Enter 5 number");
- for (int p = 0; p < 5; p++)
- {
- n[p] = Convert.ToInt32(Console.ReadLine());
- }
-
- int com = n[0];
-
-
- int temp = 0;
- for (int i = 0; i < 5; i++)
- {
- for (int j = i + 1; j < 5; j++)
- {
- if (n[i] > n[j])
- {
- temp = n[i];
- n[i] = n[j];
- n[j] = temp;
- }
- }
- }
-
- Console.WriteLine("Second Smallest Number is " + n[1]);
-
- Console.ReadKey();
Output
Find the length of string without any use of predefined function- string s;
- int c = 0;
- int noofA = 0;
- Console.Write("Enter the string: ");
- s = Console.ReadLine();
-
- foreach (char p in s)
- {
- c++;
- }
-
- Console.WriteLine("Totol Length is " +c);
- Console.ReadKey();
Output Print Pyramid Triangles - for (int p = 1; p <= 5; p++)
- {
- for (int i = p; i <= 4; i++)
- {
- Console.Write(" ");
- }
- for (int j = 1; j <= p; j++)
- {
- Console.Write(" "+p);
- }
- for (int k = p - 4; k > 1; k--)
- {
- Console.Write(" "+p);
- }
- Console.WriteLine("");
- }
-
- Console.ReadKey();
Output If this helps any one I feel pleasure.