Tuesday 15 February 2011

c# - Printing the amount of all numbers between 1 and the number. No errors and it doesnt work -


Trying TI will create a program and count all the numbers between 1 and that number will be counted . I have been asked to use the function to do this. When I run the program then no error is seen, it sees the number and after that nothing does the code:

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; System usage threading. Task; Namespace Console Application 2 {Class Program {Static Zero Main (string [] ARG) {int i; Int n = 0; Int a = 0; Console.light line ("Enter a number:"); I = (convert. ToInt32 (console .readline ())); AmountOfNumbers (Ref I, Ref N, Ref A); Console.Write (a); } Fixed Zero Amountoff number (Ref I int, ref intra n, ref I int a) {while (N & lt; i) {a + = n; }}}}   

Any help would be appreciated, thanks further.

  while (n  i)   

n can never change its value within the loop, so with n = 0 , it will end with an infinite loop where n (which is 0 ) being added to a

It is being said, the amount of number between 1 and an arbitrary integer n ( n> 1 ) n - 1 does not require any loop.

No comments:

Post a Comment