Reverse a string without any use of predefined function

  1. public static void Main()
  2. {
  3. int n = 0;
  4. Console.WriteLine("Enter a string");
  5. string s = Console.ReadLine();
  6. string rev = "";
  7. foreach (char c in s)
  8. {
  9. n++;
  10. }
  11. while (n > 0)
  12. {
  13. rev = rev + s[n - 1];
  14. n = n - 1;
  15. }
  16. Console.WriteLine(rev);
  17. Console.ReadKey();
  18. }
Output



Find out Second smallest number
  1. int[] n = new int[5];
  2. Console.WriteLine("Enter 5 number");
  3. for (int p = 0; p < 5; p++)
  4. {
  5. n[p] = Convert.ToInt32(Console.ReadLine());
  6. }
  7. int com = n[0];
  8. //sorting in ascending
  9. int temp = 0;
  10. for (int i = 0; i < 5; i++)
  11. {
  12. for (int j = i + 1; j < 5; j++)
  13. {
  14. if (n[i] > n[j])
  15. {
  16. temp = n[i];
  17. n[i] = n[j];
  18. n[j] = temp;
  19. }
  20. }
  21. }
  22. Console.WriteLine("Second Smallest Number is " + n[1]);
  23. Console.ReadKey();
Output



Find the length of string without any use of predefined function

  1. string s;
  2. int c = 0;
  3. int noofA = 0;
  4. Console.Write("Enter the string: ");
  5. s = Console.ReadLine();
  6. foreach (char p in s)
  7. {
  8. c++;
  9. }
  10. Console.WriteLine("Totol Length is " +c);
  11. Console.ReadKey();
Output



Print Pyramid Triangles
  1. for (int p = 1; p <= 5; p++)
  2. {
  3. for (int i = p; i <= 4; i++)
  4. {
  5. Console.Write(" ");
  6. }
  7. for (int j = 1; j <= p; j++)
  8. {
  9. Console.Write(" "+p);
  10. }
  11. for (int k = p - 4; k > 1; k--)
  12. {
  13. Console.Write(" "+p);
  14. }
  15. Console.WriteLine("");
  16. }
  17. Console.ReadKey();
Output



If this helps any one I feel pleasure.