
Nolemmiv
5 год назад
дан массив найти произведение отрицательных элементов С#
ОТВЕТЫ

Мстислав
Oct 24, 2020
public static void Main(string[] args)
{
const int n=15;
int[] a=new int[n];
Random rnd=new Random();
double p=1;
Console.WriteLine("массив: ");
for(int i=0;i<n;i++)
{
a[i]=rnd.Next(-10,10);
Console.Write(a[i]+" ");
if(a[i]<0) p=p*a[i];
}
Console.WriteLine();
Console.WriteLine("произведение отрицательных: "+p);
}
{
const int n=15;
int[] a=new int[n];
Random rnd=new Random();
double p=1;
Console.WriteLine("массив: ");
for(int i=0;i<n;i++)
{
a[i]=rnd.Next(-10,10);
Console.Write(a[i]+" ");
if(a[i]<0) p=p*a[i];
}
Console.WriteLine();
Console.WriteLine("произведение отрицательных: "+p);
}
387
Смежные вопросы: