You are on page 1of 15

1.

using System;

2.

using System.Collections.Generic;

3.

using System.Linq;

4.

using System.Text;

5.
6.

namespace ConsoleApplication1

7.

8.

class Program

9.

10.

static void Main(string[] args)

11.

12.

string initial = "";

13.
14.

Console.WriteLine("Enter a String to check for Palindrome");

15.
16.

string input = Console.ReadLine();

17.
18.

int iLength = input.Length;

19.
20.

if (iLength == 0)

21.

22.
23.

Console.WriteLine("You did not enter the string");

24.

25.
26.

else

27.

28.
29.

for (int j = iLength - 1; j >= 0; j--)

30.

31.

initial = initial + input[j];

32.

33.
34.

if (initial == input)

35.

36.

Console.WriteLine(input + " is palindrome");

37.

38.

else

39.

40.

Console.WriteLine(input + " is not a palindrome");

41.

42.
43.
44.

Console.Read();

45.
46.

}
}

47.

48.

49.

Output:

1.

Enter a String to check for Palindrome

2.

MADAM

3.

MADAM is palindrome

1.

Enter a String to check for Palindrome

2.

RAJAN

3.

RAJAN is not a palindrome

1.

using System;

2.
3.

namespace forgetCode

4.

5.

class Program

6.

7.

public static void Main()

8.

9.

int n;

10.

float large, small;

11.

int[] a = new int[50];

12.

Console.WriteLine("Enter the size of Array");

13.

string s = Console.ReadLine();

14.

n = Int32.Parse(s);

15.

Console.WriteLine("Enter the array elements");

16.

for (int i = 0; i < n; i++)

17.

18.

string s1 = Console.ReadLine();

19.

a[i] = Int32.Parse(s1);

20.

21.

Console.Write("");

22.

large = a[0];

23.

small = a[0];

24.

for (int i = 1; i < n; i++)

25.

26.

if (a[i] > large)

27.

large = a[i];

28.
29.

else if (a[i] < small)


small = a[i];

30.

31.

Console.WriteLine("Largest element in the array is {0}", large);

32.

Console.WriteLine("Smallest element in the array is {0}", small);

33.

34.

35.
36.

Output:
Enter the size of Array
6
Enter the array elements
23
11
98
65
54
43
Largest element in the array is 98
Smallest element in the array is 11

1.

static void Main(string[] args)

2.

3.
4.

int iPrevious = -1;

5.

int iNext = 1;

6.

int iNumber;

7.

8.
9.

Console.WriteLine("Enter the total number you want to display the series");

10.
11.

iNumber= int.Parse(Console.ReadLine());

12.
13.

for (int i = 0; i < iNumber; i++)

14.

15.
16.

int iSum = iNext + iPrevious;

17.

iPrevious = iNext;

18.

iNext = iSum;

19.
20.

Console.WriteLine(iNext);

21.

22.

Console.ReadLine();

23.

1.

using System;

2.

using System.Text.RegularExpressions;

3.
4.

namespace ForgetCode

5.

6.

public class MainClass

7.

8.

public static void Main()

9.

10.

Console.WriteLine("Program for displaying pattern of *.");

11.

Console.Write("Enter the maximum number of *: (Top to Middle line)");

12.

int n = Convert.ToInt32(Console.ReadLine());

13.
14.

Console.WriteLine("\nHere is the Diamond of Stars\n");

15.
16.

for (int i = 1; i <= n; i++)

17.

18.

for (int j = 0; j < (n - i); j++)

19.

Console.Write(" ");

20.

for (int j = 1; j <= i; j++)

21.

Console.Write("*");

22.

for (int k = 1; k < i; k++)

23.

Console.Write("*");

24.
25.

Console.WriteLine();
}

26.
27.

for (int i = n - 1; i >= 1; i--)

28.

29.

for (int j = 0; j < (n - i); j++)

30.

Console.Write(" ");

31.

for (int j = 1; j <= i; j++)

32.

Console.Write("*");

33.

for (int k = 1; k < i; k++)

34.

Console.Write("*");

35.

Console.WriteLine();

36.

37.
38.

Console.WriteLine();

39.

40.
41.
42.

}
}

Output:

1.

2.

***

3.

*****

4.

*******

5.

*********

6.

*******

7.

*****

8.

***

9.

1.

using System;

2.
3.

namespace forgetCode

4.

5.

class Program

6.

7.

public static void Main()

8.

9.

int[] a = new int[100];

10.

Console.WriteLine("Number of elements in the array ?");

11.

string s = Console.ReadLine();

12.

int x = Int32.Parse(s);

13.

Console.WriteLine("-----------------------");

14.

Console.WriteLine(" Array elements ");

15.

Console.WriteLine("-----------------------");

16.

for (int j = 0; j < x; j++)

17.

18.

string s1 = Console.ReadLine();

19.

a[j] = Int32.Parse(s1);

20.

21.

int limit = x - 1;

22.

for (int pass = 0; pass < x - 1; pass++)

23.

24.

for (int j = 0; j < limit - pass; j++)

25.

26.

if (a[j] > a[j + 1])

27.

28.

int k = a[j];

29.

a[j] = a[j + 1];

30.

a[j + 1] = k;

31.

32.
33.
34.

35.

36.

Console.WriteLine("------------------------------------------------");

37.

Console.WriteLine("Sorted elements of an array are(bubble sort)");

38.

for (int j = 0; j < x; j++)

39.

Console.WriteLine(a[j]);

40.
41.

}
}

42.

Output:
Number of elements in the array ?
4
----------------------Array elements
----------------------23
12
45
34
-----------------------------------------------Sorted elements of an array are(bubble sort)
12
23
34
45

1.

using System;

2.
3.

namespace forgetCode

4.

5.

class Program

6.

7.

public static void Main()

8.

9.

int binom = 1, q = 0, r, x;

10.
11.

//Input from the user

12.

Console.WriteLine("Enter the number of rows");

13.

string s = Console.ReadLine();

14.

int p = Int32.Parse(s);

15.
16.

Console.WriteLine("The Pascal Triangle");

17.

while (q < p)

18.

19.

//Pascal programming

20.
21.

for (r = 40 - (3 * q); r > 0; --r)

22.

Console.Write(" ");

23.

for (x = 0; x <= q; ++x)

24.

25.

if ((x == 0) || (q == 0))

26.

binom = 1;

27.

else

28.

binom = (binom * (q - x + 1)) / x;

29.

Console.Write(binom);

30.

31.

Console.Write("\n ");

32.

++q;

33.
34.

}
}

35.

36.
37.

Output:
Enter the number of rows
5
The Pascal Triangle
1
11
121
1331
14641

1.

using System;

2.
3.

namespace forgetCode

4.

5.

class Program

6.

7.

public static void Main()

8.

9.

int n;

10.

float large, small;

11.

int[] a = new int[50];

12.

Console.WriteLine("Enter the size of Array");

13.

string s = Console.ReadLine();

14.

n = Int32.Parse(s);

15.

Console.WriteLine("Enter the array elements");

16.

for (int i = 0; i < n; i++)

17.

18.

string s1 = Console.ReadLine();

19.

a[i] = Int32.Parse(s1);

20.

21.

Console.Write("");

22.

large = a[0];

23.

small = a[0];

24.

for (int i = 1; i < n; i++)

25.

26.

if (a[i] > large)

27.

large = a[i];

28.

else if (a[i] < small)

29.

small = a[i];

30.

31.

Console.WriteLine("Largest element in the array is {0}", large);

32.

Console.WriteLine("Smallest element in the array is {0}", small);

33.

34.

35.
36.

Output:
Enter the size of Array
6
Enter the array elements
23
11
98
65
54
43
Largest element in the array is 98
Smallest element in the array is 11