C#
Lab 7A: Thank you, Grace Hopper. You may have heard the story, but the programming term “bug” is attributed to the computer legend Grace Hopper who, after diagnosing the problem with a program, determined it was because a bug (in this case, a moth) physically wedged itself under a vacuum tube – causing the machine to no longer work. We’ve come a long way since then...
For this part of the lab, you are going to write a program, then show what it looks like using the debugger. So, in addition to your code, you’re going to have to submit a screenshot of the debugger.
Start by writing the following program: prompt the user for the size of an integer array, declare an array of that size, then populate each cell of the array with the square of the cell’s index (e.g. cell 0 = 0, cell 1 = 1, cell 2 = 4, cell 3 = 9). Finally, print out the contents of the array separated by the “pipe” symbol (above the Enter key) on a single line. The program should behave like the sample output below. User input is denoted in bold.
C++ students: see the appendix for example code of creating an array based off of a user variable.
Use the debugger: Once your program is working, you must set a breakpoint in your code (preferably the line that is printing out each cell), then start walking through the code. Just before the program is finished, show the array in the debugger – with each cell holding the correct value (i.e. expand the array in the debugger, just like in the video). Take a screenshot of it and save it to your desktop. In addition to your code, you will need to submit this image.
Sample #1:
Enter the size of the array: 5 |0|1|4|9|16
Sample #2:
Enter the size of the array: 14
|0|1|4|9|16|25|36|49|64|81|100|121|144|169
SOLUTION-
I have solve the problem in C# code with screenshot for easy
understanding :)
CODE-
//c# code
using System;
class HelloWorld {
static void Main() {
Console.Write("Enter the size of
array: ");
int n=
Convert.ToInt32(Console.ReadLine());
int[] a= new int[n];
int i;
for(i=0;i<n;i++)
{
a[i]=i*i;
}
for(i=0;i<n;i++)
{
Console.Write("{0}|",a[i]);
}
}
}
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE
ANSWER-----------THANK
YOU!!!!!!!!----------
Get Answers For Free
Most questions answered within 1 hours.