Hello C-Sharpcorner,
I want to know how to add numbers by 6, starting from #6
(so, 6->12->18->24.. so forth until 100)
-----------------------------------------------------------------------------------------------
private void six()
{
Console.WriteLine("the number will go up by 6");
double sixStart =6;
//Below is the nooby method that I came up with
//But I want to know if there is something better than doing this for individual numbers
Console.WriteLine("2nd # ={0}", sixStart + 6);
Console.WriteLine("3rd # ={0}", sixStart +12);
//Are there any formulas to replace this...?
}
Loading
Posted Sep 27, 2014, 7:53 PM
class Program
{
static void Main(string[] args)
{
int x = 0;
for (int i = 0; i < 16; i++)
{
x = x + 6;
Console.WriteLine(x);
}
Console.Read();
}
}
Posted Oct 5, 2014, 10:46 AM
In the following program choose whatever number you like in the FOR loop, only thing is it should be bigger than the 100 here I choose 500.
And in the IF loop make your requirement less or equal to 100 then you will obtain your required o/p.
using System;
class Program
{
static void Main(string[] args)
{
int x = 0;
for (int i = 0; i < 500; i++)
{
x = x + 6;
if (x <= 100)
Console.Write(" " + x);
else
break;
}
Console.Read();
}
}
// 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96
Song LeePosted Oct 5, 2014, 10:09 AM
Thank you for the help.
It did really save time for me :)