Thursday 23 May 2013

how to draw pattern like 123 | if condition | without using loop | comments

  how to draw pattern like 123 | if  condition | without using loop | comments
   how to draw pattern like 123 | if  condition | without using loop
            1
            12
            123.

  simple program codes showing to draw 123 pattern. Logic is very simple just  divide value using 100 , 10, and 1I have shown here code and also out put of given program in c#
        int val = 123;
        int temp = 0;

        int last = 3;
        if(last>2)
        {
            temp = val / 100; //will gives 1 because 123/100 remainder will be 23
            Response.Write(temp);
            Response.Write("</br>");
            temp = val / 10; //will gives 12 because 123/10 remainder will be 3
            Response.Write(temp);
            Response.Write("</br>");
            temp = val / 1; ////will gives 123 because 123/1 remainder will be 0
            Response.Write(temp);
           
           // just simple funda  not a very difficult source code.

Wednesday 22 May 2013

How to revese number | integer in c# | examples code | comments

How to revese number | integer in c# | examples code | comments
In this article we are going to learn how to reverse a integer or numeric number in c#.
With help of for loop i have shown the program to reverse the given number.
Don't ignore comments.

        int temp = 0;  //took temporary variable
        int val =13298765; //passed  integer value to the integer type variable val
        for (int i=0; val>0 ;i++) // now  increment of i
        {
            temp =val % 10; // storing all the   single digit  in temp variable
            val =val/10; //taking remaining value after mod
            Response.Write(temp);
        }


In this program we don't need to take length because it won't works.
it works at time of sring and array.
mod [%] will give you last value on number.
and / will store remaining one in val variable.




output :-56789231



another example
 /int count = 34;
        int temp = 0;
        while (count > 0)
        {
            temp = count % 10;
            count = count / 10;
         Response.Write(temp);



     

How to reverse string in c# | asp.net | example | output

How to reverse string in c# | asp.net | example | output
reverse string using for loop in c#  with program source code.
         In this program we are going to learn how to reverse  a string using temporary variable and
        display them at last .a very simple process .take string calculate length of string using for loop
        count it till its last character.after display it .
        i have shown program with source code. and output also .


        string temp="";  //took temporary variable
        string str = "enteryourstring"; //passed string
        int last = str.Length; //calculated length of string
        for (int i =last -1;i>=0 ; i--) // now decrement
        {
            temp = temp + str[i]; // storing all the  character in temp variable
        }
        Response.Write(temp); //display

output:gnirtsruoyretne