In: Computer Science
Write an application that reads three integers, adds all three together and computes an average of the three entries and computes any remainder of the integer division. A remainder represents the modulus result of dividing an even by an odd number or vice versa. Display the output.
Enter an integer score 3
Enter an integer score 6
Enter an integer score 4
The average of 3, 6, 4 is 4 with a remainder of
1
Press any key to continue . . .
or
Enter an integer score 3
Enter an integer score 6
Enter an integer score 9
The average of 3, 6, 9 is 6 with a remainder of
0
Press any key to continue . . .
Submit only the .cs file with your code in it.
using System;
public class Test
{
public static void Main()
{
int[] score = new int[3]; // array
of 3 integers
int avg,rem,sum = 0;
for(int i=0;i<3;i++)
{
Console.WriteLine("Enter an integer
score ");
score[i] =
Convert.ToInt32(Console.ReadLine());
sum = sum + score[i];
}
avg = sum/3;
rem = sum%3;
Console.WriteLine("The average of
"+score[0]+","+score[1]+","+score[2]+" is "+avg +" with a remainder
of "+rem);
}
}
Output:
Enter an integer score 3 Enter an integer score 6 Enter an integer score 4 The average of 3,6,4 is 4 with a remainder of 1
Do ask if any doubt. Please upvote.