Monday 3 December 2012

Swapping Two numbers

     Using 3rd Variable

void swap(int m, int n)
{
    int temp;
    temp = m;
    m = n;
    n = temp;
    printf("\nAfter Swapping, the numbers are: ");
    printf("\n\nFirst Number is: %d",m);
    printf("\nSecond Number is: %d",n);
}



          Without Using 3rd Variable

void swap(int m, int n)
{
    m = m + n;
    n = m - n;
    m = m - n;
    printf("\nAfter Swapping, the numbers are: ");
    printf("\n\nFirst Number is: %d",m);
    printf("\nSecond Number is: %d",n);
}



          Without Using 3rd Variable

void swap(int m, int n)
{
    m = m ^ n;
    n = m ^ n;
    m = m ^ n;
    printf("\nAfter Swapping, the numbers are: ");
    printf("\n\nFirst Number is: %d",m);
    printf("\nSecond Number is: %d",n);
}

OR

void swap(int m, int n)
{
    m ^= n ^= m ^= n;
    printf("\nAfter Swapping, the numbers are: ");
    printf("\n\nFirst Number is: %d",m);
    printf("\nSecond Number is: %d",n);
}



Without Using 3rd Variable but both numbers should be Non-Zero

void swap(int m, int n)
{
    if(m != 0 && n != 0)
    {
        m = m * n;
        n = m/n;
        m = m/n;    
        printf("\nAfter Swapping, the numbers are: ");
        printf("\n\nFirst Number is: %d",m);
        printf("\nSecond Number is: %d",n);
    }
    else
    {
        printf("\n Both the numbers should be Non-Zero!");
    }
}

          OR

          void swap(int m, int n)
{
    if(m != 0 && n != 0)
    {
        n = m * n;
        m = n/m;
        n = n/m;
        printf("\nAfter Swapping, the numbers are: ");
        printf("\n\nFirst Number is: %d",m);
        printf("\nSecond Number is: %d",n);
    }
    else
    {
        printf("\n Both the numbers should be Non-Zero!");
    }
}



          Swapping in a Single Line

void swap(int m, int n)
{
    n = m + n - (m = n);
    printf("\nAfter Swapping, the numbers are: ");
    printf("\n\nFirst Number is: %d",m);
    printf("\nSecond Number is: %d",n);
}

Thursday 29 November 2012

Insert date in sql server from c#

 System.Globalization.CultureInfo dateformat = new System.Globalization.CultureInfo("en-GB", true);


                DateTime fromdate = Convert.ToDateTime(txtFromdate.Text, dateformat);

How to pass QueryString Between Pages in C#

For passing variables content between pages ASP.NET gives us several choices. One choice is using QueryString property of Request Object.

Put this code to your submit button event handler.

Response.Redirect("SparePartItemReport.aspx?OrderNo=" + txtOrderNo.Text + "&Status=Inventoried");

 Our first code part builds a query string for your application and send contents of your textboxes to second page. Now how to retrieve this values from second page. Put this code to second page page_load.


 if (Request.QueryString["OrderNo"] != null && Request.QueryString["OrderNo"].ToString() != "" && Request.QueryString["Status"] != null && Request.QueryString["Status"].ToString() != "")
            {
                string OrderNo = Request.QueryString["OrderNo"].ToString();
                string Status = Request.QueryString["Status"].ToString();

}