About the function of exercise one

Source: Internet
Author: User

1, two number of the maximum value
function Getmax (A, b) {
if (a>b) {
return A;
}else{
return b;
}
}
var Max = Getmax (300,600)
Console.log (Max)
Minimum value of 2, two digits
function Getmin (A, b) {
if (a>b) {
return b;
}else{
return A;
}
Return a<b?a:b;
}
var Min = getmin (400,800)
Console.log (Min)
3, seek n-m between the and
function Getsum (n,m) {
var getsum = 0;
for (var i= n; i<=m; i++) {
getsum+= i;
}
return getsum;
}
var sum = getsum (1,10);
Console.log (SUM)
4. Calculate the area of the circle
function Getarea (r) {
var PI = 3.14;
Return Pi*r*r
}
var area = Getarea (10);
Console.log (area)
5, to seek the circumference of the circle
function Getarea (R) {
var PI = 3.14;
return 2*pi*r;
}
var area = Getarea (2)
Console.log (area)
6. Find the maximum value in three numbers
function Getmax (a,b,c) {
if (a>b && a>c) {
return A;
}else if (b>a && b>c) {
return b;
}else{
return C;
}
}
var Max = Getmax (23,34,45)
Console.log (Max)


function Getmax (a,b,c) {
var d = Math.max (A, b);
var e = Math.max (d,c);
return e;
}
var max = Getmax (100,390,500);
Console.log (max)
7, to find a group of the maximum value
var nums = [12,23,34,45,56,67,78,89,90];
var max = nums[0];
For (var i= 1; i< nums.length;i++) {
if (Max<nums[i]) {
max = Nums[i];
}
}
Console.log (max)

var nums = [12,23,34,45,56,67,78,89,90];
function Getmax (array) {
var max = array[0];
for (Var i=1;i<array.length;i++) {
if (max< Array[i]) {
max = Array[i];
}
}
return Max;
}
var max = Getmax (nums);
Console.log (max)
8. Find the minimum value of a group of numbers
var nums = [12,23,34,45,56,67,78,89,90];
function Getmin (array) {
var min = array[0];
for (Var i=1;i<array.length;i++) {
if (Min>array[i]) {
min = Array[i];
}
}
return min;
}
var min = getmin (nums);
Console.log (min)

About the function of exercise one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.