Professional Documents
Culture Documents
Lab
حنان عبد الولي.م. م/ زينة صادق.م.م 2019-2020 صباحي و مسائي
Ex1: write a vc# program to read and display elements of an array with size equal to 6 integer
numbers then finds:
1- av of numbers in odd location
2- av of odd numbers in the array
3- max number in array with its location
namespace ConsoleApplication3
{ class Program
{ static void Main(string[] args)
{// جزء التعريف
const int size = 6;
int[] aa = new int[size];
double sum = 0;
int count = 0;
double av, av1;
//// الطباعة
Console.WriteLine(" the print of orginal array");
for (int i = 0; i < size; i++)
Console.WriteLine(aa[i]);
sum = 0;
count = 0;
//// استخراج معدل االرقام الفردية
for (int i = 0; i < size; i++)
if (aa[i] % 2 == 1)
{
sum = sum + aa[i];
count++;
}
av1 = sum / count;
Console.WriteLine(av1);
//// استخراج اكبر رقم
int max = aa[0];
int loc = 0;
for (int i = 0; i < size; i++)
if (aa[i] > max)
{
max = aa[i];
loc = i;
}
Console.WriteLine(" max number =" + max);
Console.WriteLine(" location =" + loc); }
Console.ReadKey();
}
}
Programming Fundamentals2. Lab
حنان عبد الولي.م. م/ زينة صادق.م.م 2019-2020 صباحي و مسائي
The Output:
{
class Program
{
static void Main(string[] args)
{
const int size = 4;
}
}
}
Programming Fundamentals2. Lab
م.م .زينة صادق /م.م .حنان عبد الولي صباحي و مسائي 2019-2020
The Output: