using for loop pattern in C#
For Example: Write a program to print
following output using for loop.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
classProgram
{
staticvoid Main(string[] args)
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = i; j <= 5; j++) //Nested for
loop
{
Console.Write("{0}",j);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Output:
Comments
Post a Comment