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...?
}
Adding up numbers by 6
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Sep 27, 2014, 3:53 PM EDT
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();
}
}
Song Lee34 pointsPosted Oct 5, 2014, 6:09 AM EDT
Thank you for the help.
It did really save time for me :)
Former memberPosted Oct 5, 2014, 6:46 AM EDT
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