/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: enter 10 to store the data in the array, and calculate the maximum, minimum, and average values.
* Author: Lei hengxin
* Completion date: January 1, September 09, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a program that inputs 10 numbers into an array to calculate the maximum, minimum, and average values ");
Double [] c = new double [10];
For (int number = 0; number <10; ++ number)
{
Console. Write ("Enter the number of {0}:", number + 1 );
// String s = Console. ReadLine ();
C [number] = double. Parse (Console. ReadLine ());
}
// Use the foreach statement to output every element in the array cyclically
Console. Write ("You enter 10 :");
Foreach (double var in c)
{
Console. Write (var); // read the elements in the string in sequence
Console. Write ("");
}
Console. WriteLine ();
Double min1 = min (c );
Console. WriteLine ("the minimum value of the input 10 is {0}", min1 );
Double max1 = max (c );
Console. WriteLine ("the maximum number of input 10 is: {0}", max1 );
Double average1 = average (c );
Console. WriteLine ("the average value of the input 10 is {0}", average1 );
Console. ReadKey ();
}
Static double max (double [] c)
{
Double max = c [0];
For (int I = 1; I <10; ++ I)
{
If (max <c [I])
Max = c [I];
}
Return max;
}
Static double min (double [] c1)
{
Double min = c1 [0];
For (int I = 1; I <10; ++ I)
{
If (min> c1 [I])
Min = c1 [I];
}
Return min;
}
Static double average (double [] c1)
{
Double average;
Double all = 0;
/* Foreach (char var in c1)
{
All = all + var;
}*/
For (int I = 0; I <10; ++ I)
{
All = all + c1 [I];
}
Average = all/c1.Length;
Return average;
}
}
}
Running result:
Attachment:
The following program is incorrect. It is the maximum ASCII value corresponding to the calculated number.
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a program that inputs 10 numbers into an array to calculate the maximum, minimum, and average values ");
Console. Write ("Please enter 10 numbers (separated by spaces ):");
String s = Console. ReadLine ();
Char [] c = s. ToCharArray ();
Int I = c. Length;
Int j = 0;
Int [] c1 = new int [c. Length];
// Use the foreach statement to output every element in the array cyclically
Foreach (char var in c)
{
// C1 [j] = Convert. ToInt32 (var); // converts the string to an ASCII code.
C1 [j] = var;
++ J; // string reading
}
Console. Write ("You enter 10 :");
Foreach (char var in c1)
{
Console. Write (var); // read the elements in the string in sequence
}
Console. WriteLine ();
Int min1 = min (c1 );
Console. WriteLine ("the minimum value of the input 10 is {0}", min1 );
Int max1 = max (c1 );
Console. WriteLine ("the maximum number of input 10 is: {0}", max1 );
Double average1 = average (c1 );
Console. WriteLine ("the average value of the input 10 is {0}", average1 );
Console. ReadKey ();
}
Static int max (int [] c1)
{
Int n = c1.Length;
Int max = c1 [0];
For (int I = 2; I <n; I = I + 2)
{
If (max <c1 [I])
Max = c1 [I];
}
Return max;
}
Static int min (int [] c1)
{
Int n = c1.Length;
Int min = c1 [0];
For (int I = 2; I <n; I = I + 2)
{
If (min> c1 [I])
Min = c1 [I];
}
Return min;
}
Static double average (int [] c1)
{
Double average;
Int all = 0;
/* Foreach (char var in c1)
{
All = all + var;
}*/
For (int I = 0; I <c1.Length; I = I + 2)
{
All = all + c1 [I];
}
Average = all/c1.Length;
Return average;
}
}
}
Running result: