Sunday, 5 February 2012

WinApp - Click Counter

This program is a simple Windows Form Application for counting the number of clicks done don on that form and as the user clicks the number counter will increase its value by 1.

Code for the program is as follows:-


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace clickcount
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int clickcount = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            clickcount++;
            label1.Text = "number of clicks: " + clickcount + ".";
        }
    }
}

Write a C-Sharp .NET console application program for finding factorial of the given number.

Write a C-Sharp .NET console application program for finding factorial of the given number.


Program source code for finding factorial of the given number in C#.NET.

using System;
using System.Collections.Generic;
using System.Text;

namespace factorial
{
class Program
{

static void Main(string[] args)
{
int i, fact = 1, n;
String no;
Console.WriteLine("Enter a number:");
no = Console.ReadLine();
n = Convert.ToInt32(no);
for (i = 1; i <= n; i++)
{
fact = fact * i;
}
Console.WriteLine("factorial is:" + fact);
Console.ReadLine();
}
}
}

Write a C-Sharp .NET Console program to generate the following number pattern.


Write a C-Sharp .NET Console program to generate the following number pattern.
 1
22
333
4444
55555

Program Code:-

public class  ForLoop{
  public static void main(String[] args){
    for(int i = 1;i <= 5;i++){
      for(int j = 1;j <= i;j++){
        System.out.print(i);
      }
      System.out.println();
    }
  }
}

Output of the program :

1
22
333
4444
55555