|
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:  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:  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:  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. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|