0% found this document useful (0 votes)
45 views

Class Static Void Int: Program (Printarry ( (,) Arr)

The document defines functions to work with arrays in C#. It includes functions to print the contents of an array, read values into a 2D array from user input, and get the upper bound of a dimension in a 2D array. The Main function calls the reads and printArry functions to populate a 2D array from user input and display the values.

Uploaded by

user
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Class Static Void Int: Program (Printarry ( (,) Arr)

The document defines functions to work with arrays in C#. It includes functions to print the contents of an array, read values into a 2D array from user input, and get the upper bound of a dimension in a 2D array. The Main function calls the reads and printArry functions to populate a 2D array from user input and display the values.

Uploaded by

user
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

class Program

{
static void printArry( int [ ] arr )
{ //‫هذه الدالة لطباعة محتويات المصفوفة‬
foreach ( int x in arr )
Console.WriteLine("\t {0}" , x) ;
}
static void Main(string [ ] args)
{
int [ ] x = new int [ 10 ] ;
Console.WriteLine("Enter {0} Numbers." , x.Length) ;
for ( int y = 0 ; y < x.Length ; y++)
{ // ‫إضافة بيانات إلى المصفوفة‬
Console.Write("{0}- Enter a Number : " , y + 1 ) ;
x [ y ] = Convert.ToInt32( Console.ReadLine() ) ;
}
printArry( x ) ; // ‫طباعة عناصر المصفوفة‬
Console.Write("Enter Search Number : ") ;
int z = Convert.ToInt32( Console.ReadLine() ) ;
bool fnd = false ;
for ( int y = 0 ; y < x.Length ; y++)
{ // ‫للبحث عن قيمة ضمن المصفوفة‬
if (x [ y ] == z)
{
Console.WriteLine("The Number ( {0} ) Found On Index Number {1}" , z , y ) ;
fnd = true ;
break ; }
}
if (fnd == false) Console.WriteLine("The Number ( {0} ). Not Found!" , z ) ;

bool [ ] found = new bool [ x.Length ] ;


for ( int t = 0 ; t < x.Length ; t++)
{ // ‫عد العناصر المتشابهة في المصفوفة‬
int sum = 1 ;
for (int tt = t + 1 ; tt < x.Length ; tt++)
{
if (found [ tt ] == false)
{
if (x [ t ] == x [ tt ] )
{
found [ tt ] = true ;
sum++ ;
}
}
}
if (found [ t ] == false)
Console.WriteLine("The Number ( {0} ) Found {1} Times ." , x[ t ] , sum ) ;
}
Console.WriteLine ( "Print Array Element Before Reverse." ) ;
printArry ( x ) ; // ‫طباعة عناصر المصفوفة قبل عكس عناصرها‬
Array.Reverse ( x ) ; // ‫عكس عناصر المصفوفة‬
Console.WriteLine ( "Print Array Element After Reverses." ) ;
printArry ( x ) ; // ‫طباعة عناصر المصفوفة بعد عكس عناصرها‬
int [ ] x2 = ( int [ ] ) x.Clone () ; // ‫نقل مصفوفة الى مصفوفة أخرى‬
Console.WriteLine ( "Print New Array Copied From Another Array." ) ;
printArry ( x2 ) ; // ‫طباعة عناصر المصفوفة الجديدة‬
}
}
class Program
{
static void printArry(int[,] arr)
{ //‫هذه الدالة لطباعة محتويات المصفوفة‬
int numOfRows = arr.GetLength(0);
int numOfColumn = arr.GetUpperBound(1);
for (int x = 0; x < numOfRows; x++)
{
for (int y = 0; y <= numOfColumn; y++)
{
Console.Write(" {0} ", arr[x, y]);
}
Console.WriteLine();
}
}
static int[,] reads()
{
int x, y;
do
{
Console.Write("Enter Num Of Rows : ");
x = Convert.ToInt32(Console.ReadLine());
} while (x <= 0);
do
{
Console.Write("Enter Num Of Column : ");
y = Convert.ToInt32(Console.ReadLine());
} while (y <= 0);
int[,] arr = new int[x, y];
for (int j = 0; j < x; j++)
{
for (int k = 0; k < y; k++)
{
Console.Write(" : ");
arr[j, k] = Convert.ToInt32(Console.ReadLine());
}
}
return arr;
}

static void Main(string[] args)


{
int[,] x = reads();
printArry(x);
int K = x.GetUpperBound(1);
Console.ReadLine();
}
}

You might also like