C# program to print average of given 3 numbers

Views: 1   

Following program shows you how to print average of given 3 numbers.
In this program we get inputs from user and calculate average of given 3 numbers using following formula
Average of given 3 numbers = (input1 + input2 + input3) / 3

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine ("Enter first number:");
    int input1 = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine ("Enter second number:");
    int input2 = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine ("Enter third number:");
    int input3 = Convert.ToInt32(Console.ReadLine());
    int result = (input1 + input2 + input3) / 3;
    Console.WriteLine("The average of three numbers: " + result);
  }
}

Output:

Enter first number:
 12
Enter second number:
 15
Enter third number:
 18
The average of three numbers: 15
On By