Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. Use variable number of arguments.

SHARE:

Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. Use variable number of arguments.




using System;

    class MinMaxSumAvrgProductOfIntegers
    {
        static int Min(params int[] sequence)
        {
            int sequenceLength = sequence.GetLength(0);
            if (sequenceLength > 0)
            {
                if (sequenceLength == 2)
                {
                    return sequence[0] < sequence[1] ? sequence[0] : sequence[1];
                }
                else
                {
                    int result = sequence[0];
                    for (int i = 1; i < sequenceLength; ++i)
                    {
                        result = Math.Min(result, sequence[i]);
                    }
                    return result;
                }
            }
            else
            {
                return 0;
            }
        }

        static int Max(params int[] sequence)
        {
            int sequenceLength = sequence.GetLength(0);
            if (sequenceLength > 0)
            {
                if (sequenceLength == 2)
                {
                    return sequence[0] > sequence[1] ? sequence[0] : sequence[1];
                }
                else
                {
                    int result = sequence[0];
                    for (int i = 1; i < sequenceLength; ++i)
                    {
                        result = Max(result, sequence[i]);
                    }
                    return result;
                }
            }
            else
            {
                return 0;
            }
        }

        static int Sum(params int[] sequence)
        {
            int sum = 0;
            foreach (int x in sequence)
            {
                sum += x;
            }
            return sum;
        }

        static int Average(params int[] sequence)
        {
            int sum = 0, sequenceLength = sequence.GetLength(0);
            foreach (int x in sequence)
            {
                sum += x;
            }

            return sum / sequenceLength;
        }

        static int Product(params int[] sequence)
        {
            if (sequence.GetLength(0) > 0)
            {
                int product = 1;
                foreach (int x in sequence)
                {
                    product *= x;
                }

                return product;
            }
            else
            {
                return 0;
            }
        }

        static void Main(string[] args)
        {
            int min = Min(6, 3, 2);
            int max = Max(6, 3, 2);
            int sum = Sum(6, 3, 2);
            int average = Average(6, 3, 2);
            int product = Product(6, 3, 2);

            Console.WriteLine("Min: {0}.\nMax: {1}.\nSum: {2}.\nAverage: {3}.\nProduct: {4}.", min, max, sum, average, product);
        }
    }

COMMENTS

Name

ADOBE ILLUSTRATOR,5,Advantages of it,14,Android,3,Android App,1,Annoucements,5,Apple,27,Apple TV 2,1,Apps,3,AutoDraw,1,Basic It,23,best rct game,4,best rct version,2,best roller coaster tycoon game,2,Black Desert Tamer,1,Blogger,1,c# tutorials,25,Cloud Computing,1,Color Schemes,1,console,1,Crowdfunding,2,Devices,1,Dock,2,elcapitan,1,Enterprise,1,Excel,1,FaceTime,1,Far Cry Primal,1,Farmville 2,5,Featured,2,Games,13,games for ios,1,Glossary,2,Google,1,google docs,1,google sheets,1,Html,3,iDevice,5,ios,1,iOS Apps,5,iOS Tweaks,1,iPhone 5,3,iPhone 5S,2,It Tricks,10,jailbreak rct,1,java,1,javascript,1,Just Cause 2,1,leeter hero,1,Mac OS X,8,macos,1,macOS,3,malwares,1,marriage in stardew valley,1,marriage stardew valley,1,Mavericks,1,Microsoft,1,Mount and Warblade,1,New Technology,6,optical character recognition,1,osx,1,php,1,Pillars of Eternity,1,PS4,1,RCT,5,RCT 2,1,RCT 3,3,rct 3 cheat,1,rct 4 hack,1,rct3,1,rct3 cheats,1,rct4,3,rct4 hack,1,RCT4 Mobile,4,rct4 redeem codes 2016,1,rct4 redeem codes 2017,1,roller coaster 3 cheats,1,rollercoaster tycoon 3,1,rollercoaster tycoon 3 money,1,rollercoaster tycoon 3 money cheat,1,Security,1,sierra,1,Sony,1,Sql,1,Stardew Valley,3,Stardew Valley Marriage,1,Store,1,Surface,1,Tamil,2,Tech,1,Ui Design,1,unflod malware,1,unlimited coins rct 4,1,Updates,1,Webdesign,5,Word,9,Wordpress,3,yosemite,1,Youtube,1,
ltr
item
Lankaitschool | Lanka itschool: Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. Use variable number of arguments.
Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. Use variable number of arguments.
https://3.bp.blogspot.com/-Ft3KXvgPObI/Wv2pTldttGI/AAAAAAAAE8k/a9vEDT0xkuwk8L0AQw42ByCmyOoFHjIgACK4BGAYYCw/s640/maxresdefault.jpg
https://3.bp.blogspot.com/-Ft3KXvgPObI/Wv2pTldttGI/AAAAAAAAE8k/a9vEDT0xkuwk8L0AQw42ByCmyOoFHjIgACK4BGAYYCw/s72-c/maxresdefault.jpg
Lankaitschool | Lanka itschool
http://www.lankaitschool.com/2018/05/write-methods-to-calculate-minimum.html
http://www.lankaitschool.com/
http://www.lankaitschool.com/
http://www.lankaitschool.com/2018/05/write-methods-to-calculate-minimum.html
true
7411958204546789358
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy