Some Example for ' for Loop '
Example no. 1
using System;
class Circle
{
public static void first()
{
int a,b,c,d;
Console.Write("Enter value:{0}");
d=Convert.ToInt32(Console.ReadLine());
for(a=1;a<=d;a++)
{
for(b=1;b<=d-a;b++)
{
Console.Write(" ");
}
for(c=1;c<=(2*a)-1;c++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
class Call
{
public static void Main()
{
Circle.first();
}
}
Example 2
using System;
class Circle
{
public static void first()
{
int a,b,d;
Console.Write("Enter value:{0}");
for(a=1;a<=d;a++)
{
for(b=1;b<=a;b++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
class Call
{
public static void Main()
{
Circle.first();
}
}
Example 3:
using System;
class Circle
{
public static void first()
{
int a,b,d;
Console.Write("Enter value:{0}");
d=Convert.ToInt32(Console.ReadLine());
for(a=d;a>=1;a--)
{
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
class Call
{
public static void Main()
{
Circle.first();
}
}
No comments:
Post a Comment