w3resource
C# Sharp Programming Exercises

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.

C# Sharp: Read and Print elements of an array

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:

Flowchart: Read and Print elements of an array

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: C# Sharp Array Exercises with Solution.
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?



New Content: Composer: Dependency manager for PHP, R Programming