Monday, September 17, 2018

Factorial Of Given Number in c#:

            int factnumber = 6;
            int fact = 1;
            for (int i = factnumber; i > 0; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine("\nFact :" + fact);

1. Sum OF Given number c#.

2. Reverse  a number c#.

3. Count 1 in given number c#.

string getnumber = "";
            int sum = 0;
            Console.Write("Enter No :");
            getnumber = Console.ReadLine();
            int one = 0;
            for (int i = 0; i < getnumber.Length; i++)
            {
                string s = getnumber[i].ToString();
                if (s == "1")
                {
                    one++;
                }
                sum = sum + Convert.ToInt32(s);
            }

            Console.WriteLine("Sum Of Digits Of No :"+sum);
            Console.WriteLine("No of One :" + one);
            Console.Write("Reverse No.");
            for (int i = getnumber.Length - 1; i >= 0; i--)
            {
                Console.Write(getnumber[i]);
            }

Csharp program to print a Rhombus:

for (int i = 1; i <= 5; i++)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
            for (int i = 4; i > 0; i--)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

output : 

1
212
32123
4321234
32123
212
1

Csharp program to print Rhombus of numbers:

 int nu = 5;
            for (int i = 1; i <= nu; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                for (int j = i - 2; j > 0; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

Output :
1
121
12321
1234321

Pattern-1:

output:

    1
   121
  12321
 1234321
123454321

Code:

            int nu = 5;
            for (int i = 1; i <= nu; i++)
            {
                int kk = ((nu-i) +(nu - i)) / 2;
                for (int y = 0; y < kk; y++)
                {
                    Console.Write(" ");
                }

                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
                for (int j = i - 1; j > 0; j--)
                {
                    Console.Write(j);
                }

                for (int y = 0; y < kk; y++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine();
            }

Tuesday, September 11, 2018

Export HTML to Excel In window application c#.


 string str = @" <table>
                                    <thead>
                                      <tr>
                                        <th>Firstname</th>
                                        <th>Lastname</th>
                                        <th>Email</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <tr>
                                        <td>John</td>
                                        <td>Doe</td>
                                        <td>john@example.com</td>
                                      </tr>
                                      <tr>
                                        <td>Mary</td>
                                        <td>Moe</td>
                                        <td>mary@example.com</td>
                                      </tr>
                                      <tr>
                                        <td>July</td>
                                        <td>Dooley</td>
                                        <td>july@example.com</td>
                                      </tr>
                                    </tbody>
                                  </table>";
                File.WriteAllText(filename,str);

Friday, September 7, 2018

Value Type:

Value type contain it's own value .
for example:
int i=100;
Refrence Value Example: