Quote of the day

Thursday, January 06, 2011

print * in vertical

I remember one day in the year 2006, my cousin Senthil Kumaran asked me to write a program in C language to print *(stars) vertically like below:

Ha ha, really I didn't even try or know actually. Later I learned few programming languages of my own and got help from others including Senthil dha.
I have a little free time these days and was thinking to do something useful. So started writing string manipulating programs using c#. Today, this vertical star striked in my mind. As I don't have Turbo C or C++, I did it in Microsoft C#.

Below is the code for printing the *s vertically based on the numbers entered in the textbox:
Output:

My output has '+' instead of ' ' (space), because I've used asp.net label to display the stars and it does not accepts multiple spaces.However, it supports in c# console application.

My trick was to print spaces before printing * in each line till the count. For example, if the number entered is 5, the first line would print 4 spaces and then a *, the next line would print 3 spaces and then 2 *s and so on.
Console application code:


Console application output:

I'm not sure about other ways of printing. If anybody knows, then let me know.



Wednesday, January 05, 2011

swapping numbers without temp variable in c#

We all know, swapping numbers with temp variable is possible and easy. Recently I just rememberd of one of the interview questions "swap 2 numbers without using temp variable". I started thinking and did that in c#.

Following is the code which swaps 2 numbers without using temp variable


Output:

I was struggling by trying with different formulae, but nothing worked. I didn't think that we can recalculate first variable for resulting the output.
I got the idea from this post answered by this member.

Tuesday, January 04, 2011

fibonacci series using c#

Following code generates fibonacci series using c#. The output is displayed in asp.net Label. The textbox gets the no. of fibonacci series.


Output

take distinct values using c#

Following code displays only the distinct values entered in a textbox using (,)comma separator.

Output:

super happy coding.....

reverse words in a sentence using c#

Following code reverses the words in a sentence. It is done in c#. I've used asp.net Label to display the output.


Output: