Skip to content

Instantly share code, notes, and snippets.

@AmirMahdyJebreily
Created June 21, 2023 18:18
Show Gist options
  • Save AmirMahdyJebreily/b5087b28e7b09367248056106a489943 to your computer and use it in GitHub Desktop.
Save AmirMahdyJebreily/b5087b28e7b09367248056106a489943 to your computer and use it in GitHub Desktop.
Get averrage with c#
// Code Agha => https://github.com/AmirMahdyJebreily
Console.Write("Enter dads count here : ");
Console.ForegroundColor = ConsoleColor.Cyan;
int count = int.Parse(Console.ReadLine());
int[] dads = new int[count];
Console.ResetColor();
Console.WriteLine();
for (int i = 0; i < count; i++)
{
Console.Write($"\tEnter dad no.{i} here : ");
Console.ForegroundColor = ConsoleColor.Cyan;
dads[i] = int.Parse(Console.ReadLine());
Console.ResetColor();
}
// کیسه
float sum = 0;
foreach (int dad in dads)
{
sum += dad;
}
float avg = (float)(sum / count);
Console.WriteLine($"\n\nSum is : {sum}");
Console.WriteLine($"Avg is : {avg}");
// int.Parse(string); float.Parse(string);
// float & double & decimal
// $"Hello {kobra}"
// (float)(sum / count)
// float => int : 1/999999999 => 1
// string ×> int : "abc123" => ????
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment