0

How can we print average of 5 number using if else

22nd Jun 2016, 12:29 PM
Jyoti Gupta
Jyoti Gupta - avatar
4 Respostas
+ 7
You can use LINQ. using System.Linq ... static void Main() { int[] mas = {4, 6, 5, 2, 3}; double result = mas.Average(); // computes the average of sequence }
25th Jun 2016, 12:13 PM
Andrii Tymochko
+ 4
there is no need of if else for finding average of 5 numbers
22nd Jun 2016, 4:11 PM
Hemant Gosavi
Hemant Gosavi - avatar
+ 4
int[] nums = new int[5]; int sum = 0; for (int i = 0; i < nums.Length; i++) { Console.Write("Enter num"+(i+1) +": "); nums[i] = int.Parse(Console.ReadLine()); sum+= nums[i]; } int ave = sum/5; Console.WriteLine("Ave: " + ave); NO NEED FOR IF ELSE. Hope that helps!
22nd Jun 2016, 4:18 PM
Erwin Mesias
Erwin Mesias - avatar
+ 2
@Andrii Tymochko the fourth question was wrong
7th Jan 2017, 10:56 PM
Nima Moradi
Nima Moradi - avatar