Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C# (C Sharp) NOT C or C++ The above contains an incomplete source code of

ID: 3876902 • Letter: U

Question

Using C# (C Sharp) NOT C or C++

The above contains an incomplete source code of a C# program which is supposed to accept any numbers of integers entered at the command line and display their sum.

Because two lines in the above given sum.cs are not totally completed, it cannot be compiled and executed. There is one line you must complete for the for-loop to work, and another line needs to be fixed so it displays the sum on screen.

using System; class CNT4704Lab public static void Main(stringll myInput) int i, sum 0 Console.WriteLine (" You entered"myInput.Length + " numbers:" // Problem (1) Something is missing from the header of the 'for' statement. // Hint: the syntax of for-loop in c# is the same as Java or C or for ) Console.Write (myInput[i]+ "") sum sum Int32 . Parse (myInput [i] ) ;

Explanation / Answer

class CNT4047Lab
{
public static void Main(string[] myInput)
{
int i,sum=0;
Console.WriteLine(" You entered "+myInput.Length+" numbers:" );
  
//for loop:you need to provide conditions ,run loop from when i=0 to i < array length and increase one by one
for(i=0;i<myInput.Length;i++){
Console.Write(myInput[i]+" ");
sum=sum+Int32.Parse(myInput[i]);
}
//you are not printing sum for printing it add it
Console.WriteLine(" Sum of your input numbers = " + sum);
Console.WriteLine(" Good Bye!");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote