C# Program: To Find Avereage Of 5 Numbers Entered By User

Sunday, 12 February 2012
using System;
class Average5
{
    public static void Main()
    {
        int number1,number2,number3,number4,number5,avg,sum;
        Console.WriteLine("Enter 5 Numbers:");
        number1=Convert.ToInt32(Console.ReadLine());
        number2=Convert.ToInt32(Console.ReadLine());
        number3=Convert.ToInt32(Console.ReadLine());
        number4=Convert.ToInt32(Console.ReadLine());
        number5=Convert.ToInt32(Console.ReadLine());
        sum=(number1+number2+number3+number4+number5);   
        avg=(sum/5);
        Console.WriteLine("The Sum Is:"+sum);
        Console.WriteLine("The Average Is:"+avg);
    }
}
OUTPUT:-

4 comments:

  1. This comment has been removed by the author.
  1. Rmh said...:

    you can also do it by this code , via for loop .. to reduce the code line :

    using System;

    class Program
    {
    static void Main()
    {
    int sum = 0;

    for(int i=0; i<5; i++)
    {
    Console.WriteLine("Enter the Integers");
    sum = sum + Convert.ToInt32(Console.ReadLine());
    }

    Console.WriteLine("sum = {0}", sum);
    Console.WriteLine("Average = {0}", sum/5);

    Console.ReadLine();
    }
    }

  1. Mounika said...:

    Useful information.I am actual blessed to read this article.thanks for giving us this advantageous information.I acknowledge this post.and I would like bookmark this post.Thanks
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

  1. Thanks for sharing The Information The Information shared is very valuable Please keep Updating us Time Just went on redaing the article Python Online Training AWS Online Training Devops Online Training Data Science Online Training

Post a Comment