I Have A Problem With The Output Using Arrays With Loops. Can You Help?
Here is an example of how to print all the values in an array of 10 elements using a for loop. Int[] arr = new int[10]; for (int x = 0; x < 10; x++) Console.WriteLine(arr[x]); but when I run this code in c# it displays 9 zeroes...How come? Could you explain to me where the mistakes are and what would be the output for this code?
1 Answer - Sort by: Date | Rating
In this example you are just making an array not assigning a value to it. So for this you can run the following code
int[] arr = new int[10];
for (int x = 0; x < 10; x++)
{
arr[x]=x; // this will assign the value in the array
Console.WriteLine(arr[x]);
}
or check out the following site.
learn-programming
int[] arr = new int[10];
for (int x = 0; x < 10; x++)
{
arr[x]=x; // this will assign the value in the array
Console.WriteLine(arr[x]);
}
or check out the following site.
learn-programming
1
0
- What Data Redundancy In Database?
- Write A Program To Find Out How Many Upper Case Letter In A String Line?
- Why We Use This Method In Java?
- What Is A Paper Based System?
- What Is The Difference Between DBMS And File Management?
- What Are The Benefits Of Using Database Approach?
- Why Java Not Supports Multiple Inheritence?
- What Is Difference Between For And Nested For Loops?
- How Do You Feel About Database?
- How To Search Input Numbers?
- Is This A Legitimate Program?
- How To Program Uniden Bearcat BC350A?
- What Are The Advantages Of A Pointer Variable?
- What Is The Role Of Target Language In Compiler Concept?
- What Was The First Couple Languages?
- Is It Possible To Create And Use A Master Page Without Using ASP.net For My Html Code? If So, What Do You Use?
- What Are The Five Basic Types Of Files In File Organization?
- What Are The 5 Basic Types Of File?
- Create A JavaScript Function That Finds The Average Of Three (3) Values, Which Are Sent To The Function When Called?
- State The Output That Will Be Produced By The Following C++ Program : #include #include Int Square (int Y ) { Return Y*y; } Void Main ( ) { For(int X=1;x?
- Find Error(s) In Each Of The Following Code Segment And Write The Correct Statement ? I.) X=1; While(x=10); Cout
- Explain The Difference Between PROGRAMMER DEFINED FUNCTION PRE-DEFINED FUNCTION By Using Examples?
- What Object Is A Mitochondrion Similar To?
- What Was The First String Instrument In America?
- What Are The Differences Between System S/w And Application S/w?

New Comment - Comments are editable for 5 min.