Write a program in C# Sharp to store elements in an array and print it

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to store elements in an array and print it

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

الأجوبة

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");	
  }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...