dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

To print the numbers using C# .net


Posted Date: 11 Jul 2012      Posted By:: Lakshmi     Member Level: Bronze    Member Rank: 0     Points: 5   Responses: 3



I want to print the numbers like below. i.e my out put patteren should be like below.

1
2,3
4
5,6,7
8
9,10,11,12


any one give me solution for this problem in generic manner

iam trying like this

for (int i = 1; i < 13; i++)
{
switch (i)
{
case 1: Console.WriteLine(i);
break;

case 4: Console.WriteLine("\n" + i);
break;
case 8: Console.WriteLine("\n" + i);
break;
default:
{
Console.Write(i+",");
break;
}
}
}

o/p:

1
2,3,
4
5,6,7,
8
9,10,11,12,

how to remove the cammas after last value




Responses

#679856    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

You can write the condition as


default:
{
if(i+1 == 13)
{
Console.Write(i);
}
else
{
Console.Write(i+",");
}
break;
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#679869    Author: chandramohan      Member Level: Gold      Member Rank: 221     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

public static void PrintNext(i) {
if (i <= 100) {
Console.Write(i + " ");
PrintNext(i + 1);
}
}

public static void Main() {
PrintNext(1);
}



 
#679871    Author: asdfg      Member Level: Gold      Member Rank: 952     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

@Anil Kumar Pandey: Still comma is displaying
@chandramoham: displaying 1 - 100 numbers






 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Calling constructor from constructor
Previous : I have one doubt on oops concept
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.