I thought about how to make the algorithm and this is the best I could come up withMitch, an algorithm is like a recipe. You should have a list of step by step instructions of how to bake a cake. This is called procedural programming. Unfortunately, what you have been doing is that you've been describing things in terms of end results and/or characteristics of the final result. As great as that is when presenting the cake in a cooking show just saying "a chocolate cake with vanilla filling, mocha butter frosting, and chocolate crumbles on top" is not going help anybody watching the show unless the show actually presents how to get to that end product.
Did you test that algorithm with pen and paper to see whether it produced the correct result for various inputs? Did you consider whether any steps were too vague or could actually be broken down into several smaller steps? For instance, what does this really mean:I thought about how to make the algorithm and this is the best I could come up with
step 1:
get the list of numbers
step 2:
take each number in the list and divide it by 2
step 3:
get the answer from previous step and check if the answer is equal to 0
step 4:
get all the answers that are equal to 0
step 5:
take away the first 9 numbers from that list
step 6;
print the only number remaining (10th number)
That is both vague and composite.get all the answers that are equal to 0
Thank youDeclare a counter variable as int count=0 outside of the loop
now traverse the loop from the i=0 to the array.length
check if array of i-th index %2==0 and counter==10
then print (array of i-th index)
else
counter=counter+1;
Oky i will try and break it down moreDid you test that algorithm with pen and paper to see whether it produced the correct result for various inputs? Did you consider whether any steps were too vague or could actually be broken down into several smaller steps? For instance, what does this really mean:
That is both vague and composite.
/// <summary>
/// Provides a variety of numeric methods
/// </summary>
public class Matherator
{
#region Constructor
/// <summary>
/// Constructor
/// </summary>
public Matherator()
{
}
#endregion
#region Methods
/// <summary>
/// Prints the numbers from 1 to 10
/// </summary>
public void PrintOneToTen()
{
for (int input = 1; input <= 10; input++)
{
Console.Write(" " + input);
}
}
/// <summary>
/// Prints the numbers from m to n
/// </summary>
/// <param name="m">m</param>
/// <param name="n">n</param>
public void PrintMToN(int m, int n)
{
for (int i = m; i <= n; i++)
{
Console.Write(" " + i );
}
}
/// <summary>
/// Returns the tenth even number, with 2 as the first even number
/// </summary>
/// <returns>tenth even number</returns>
public int GetTenthEvenNumber()
{
List<int> list = new List<int>();
for (int i = 2; i <= 2 * 10; i += 2)
{
list.Add(i);
}
return list[list.Count - 1];
}
/// <summary>
/// Returns the nth even number, with 2 as the first even number
/// </summary>
/// <param name="n">n</param>
/// <returns>nth even number</returns>
public int GetNthEvenNumber(int n)
{
// delete code below; only included so we could compile
List<int> nthEven = new List<int>();
for (int i = 2; i <= 2 * n; i += 2)
{
nthEven.Add(i);
}
return nthEven[nthEven.Count - 1];
}
#endregion
}
Console.WriteLine()
after your loop to go to the next line.The algorithm was just for the 10th number part the rest i did previouslySomething doesn't feel right. The algorithm that you came up with does not match up with the code that you actually wrote.
And also i saw that the answer would be 20 so i changed the code a bit because it felt easierSomething doesn't feel right. The algorithm that you came up with does not match up with the code that you actually wrote.