106 378
Assignments Done
95.9%
Successfully Done
In June 2022

# Answer to Question #42015 in Engineering for sam

Question #42015
Find the smallest number in an array and calculate total no. of comparison operators, assignment operations, and how many times the loop will be executed and total time it will take.
1
2014-05-09T07:16:53-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q42015
{
class Program
{
static void Main(string[] args)
{
List<long> array = new List<long>();
Random rnd = new Random();
int num =0;
for (int i = 0; i < 10000000; i++)
{
num = rnd.Next(0, Int32.MaxValue);
}
Method(array.ToArray());
}
static long? Method(long[] array)
{
if (array == null) return null;
if(array.Length<1) return null;
DateTime now = DateTime.Now;
long min = array[0];
int k = 0,j=1;

for (int i = 1; i < array.Length; i++,k++)
{
if (array[i] < min)
{
min = array[i];
j++;
}
}
DateTime after = DateTime.Now;
TimeSpan time= after - now;
Console.WriteLine("The smallest number: "+min);
Console.WriteLine("Total time: "+(time.Milliseconds+time.Seconds*1000)+" miliseconds");
Console.WriteLine("Total number of assignment operations: "+(3+k+j));
Console.WriteLine("Total number of comparison operations: " + (2 + k * 2));
Console.WriteLine("The loop was executed: "+ k +" time(s)");
return min;
}
}
}
﻿

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!