Write a program in C# Sharp to read 5 numbers enter by user and find their sum and average.
Like user Enter 1,2,3,4,5
The sum of 5 number is
1+2+3+4+5 = 15
The Average is
15/5 = 3
Sample Solution
C# Sharp Code
The Sum is: 15
The Avg is: 3
Like user Enter 1,2,3,4,5
The sum of 5 number is
1+2+3+4+5 = 15
The Average is
15/5 = 3
Sample Solution
C# Sharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3, n4, n5, sum, avg;
Console.WriteLine("Enter Five number");
n1 = Convert.ToInt32(Console.ReadLine());
n2 = Convert.ToInt32(Console.ReadLine());
n3 = Convert.ToInt32(Console.ReadLine());
n4 = Convert.ToInt32(Console.ReadLine());
n5 = Convert.ToInt32(Console.ReadLine());
sum = (n1 + n2 + n3 + n4 + n5);
avg = (sum / 5);
Console.WriteLine("The sum is: {0}", sum);
Console.WriteLine("The Avg is: {0}", avg);
Console.ReadLine();
}
}
}
Sample Outputusing System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3, n4, n5, sum, avg;
Console.WriteLine("Enter Five number");
n1 = Convert.ToInt32(Console.ReadLine());
n2 = Convert.ToInt32(Console.ReadLine());
n3 = Convert.ToInt32(Console.ReadLine());
n4 = Convert.ToInt32(Console.ReadLine());
n5 = Convert.ToInt32(Console.ReadLine());
sum = (n1 + n2 + n3 + n4 + n5);
avg = (sum / 5);
Console.WriteLine("The sum is: {0}", sum);
Console.WriteLine("The Avg is: {0}", avg);
Console.ReadLine();
}
}
}
The Sum is: 15
The Avg is: 3
No comments:
Post a Comment