C# Sharp Exercises: Read and Print elements of an array
C# Sharp Array: Exercise-1 with Solution
Write a program in C# Sharp to store elements in an array and print it.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise1
{
public static void Main()
{
int[] arr = new int[10];
int i;
Console.Write("\n\nRead and Print elements of an array:\n");
Console.Write("-----------------------------------------\n");
Console.Write("Input 10 elements in the array :\n");
for(i=0; i<10; i++)
{
Console.Write("element - {0} : ",i);
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("\nElements in array are: ");
for(i=0; i<10; i++)
{
Console.Write("{0} ", arr[i]);
}
Console.Write("\n");
}
}
Sample Output:
Read and Print elements of an array: ----------------------------------------- Input 10 elements in the array : element - 0 : 2 element - 1 : 4 element - 2 : 6 element - 3 : 8 element - 4 : 10 element - 5 : 12 element - 6 : 14 element - 7 : 16 element - 8 : 18 element - 9 : 20 Elements in array are: 2 4 6 8 10 12 14 16 18 20
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: C# Sharp Array Exercises Home.
Next: Write a program in C# Sharp to read n number of values in an array and display it in reverse order.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework