Koding C# menentukan jumlah indeks
menentukan jumlah indeks
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Kuis_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hidayat maulana");
Console.WriteLine();
Console.Write("Jumlah Indeks : ");
int
n = int.Parse(Console.ReadLine());
Console.WriteLine();
input(n);
Console.ReadLine();
}
static void input(int n)
{
double[]
x = new double[n];
for
(int i = 0; i < n; i++)
{
Console.Write("Masukkan nilai array ke " + i + ":");
double
a = double.Parse(Console.ReadLine());
x[i] = a;
}
Console.WriteLine();
func(x, n);
}
static void func(double[] x,
int n)
{
double
temp = 0;
for
(int i = 0; i < n; i++)
{
temp = temp + x[i];
}
Console.WriteLine("Jumlah = " + temp);
double
avg = temp / n;
Console.WriteLine("Rata-rata = " + avg);
max(x, n);
}
static void max(double[] x, int n)
{
double
max = x[0];
for
(int i = 0; i < n; i++)
{
if
(x[i] > max)
{
max = x[i];
}
}
Console.WriteLine("Nilai Terbesar = " + max);
min(x, n);
}
static void min(double[] x, int n)
{
double
min = x[0];
for
(int i = 0; i < n; i++)
{
if
(x[i] < min)
{
min = x[i];
}
}
Console.WriteLine("Nilai Terkecil = " + min);
}
}
}
0 komentar: