using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n;
int[] min;
int p1 = 0, max = 9999;
Console.WriteLine("PROGRAM FIND MAXIMUM NUMBER ");
Console.WriteLine("-----------------------------------");
Console.Write("Enter Number you want to Find = ");
String s = Console.ReadLine();
n = int.Parse(s);
min = new int[n];
for (int i = 0; i < min.Length; i++)
{
Console.Write("Enter Number {0} = ", i + 1);
string s2 = Console.ReadLine();
min[i] = int.Parse(s2);
if (min[i] < max)
max = min[i];
}
Console.WriteLine("------------------------------------");
Console.WriteLine("NUMBER MINIMUM IS = " + max);
for (int i = 0; i < n; i++)
{
p1 += min[i];
}
Console.Write("Sum Of Total Number = {0} ", p1);
Console.Read();
}
}
}
Tag : .NET, C#
Date :
2011-11-08 16:46:56
By :
ben
View :
1075
Reply :
3
No. 1
Guest
ผมว่าน่าจะยังไม่ค่อยเข้าใจเกี่ยวกับการรับส่งตัวแปรนะครับ
int สามารถมาใส่ Double ได้ แต่ Double ไม่สามารถมาใส่ int ไม่ได้นะครับ ต้องระวัง
ถ้าจาก Code mเราทำมาจะให้ใส่ทศนิยมได้ก็ประมาณนี้นะครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n;
double max = 9999;
double[] min;
double p1 = 0;
Console.WriteLine("PROGRAM FIND MAXIMUM NUMBER ");
Console.WriteLine("-----------------------------------");
Console.Write("Enter Number you want to Find = ");
String s = Console.ReadLine();
n = int.Parse(s);
min = new double[n];
for (int i = 0; i < min.Length; i++)
{
Console.Write("Enter Number {0} = ", i + 1);
string s2 = Console.ReadLine();
min[i] = double.Parse(s2);
if (min[i] < max)
max = min[i];
}
Console.WriteLine("------------------------------------");
Console.WriteLine("NUMBER MINIMUM IS = " + max);
for (int i = 0; i < n; i++)
{
p1 += min[i];
}
Console.Write("Sum Of Total Number = {0} ", p1);
Console.Read();
}
}
}