Home > Net >  The zha get ah
The zha get ah

Time:10-01

In the same class defined in different ways, to achieve the following functions:
(1) design a method of calculation of 1-100 between the sum of all the multiples of 3 Numbers, and returns the value;
(2) for a given any two integers, calculate the number of the two least common multiple, and the number 3 output;
(3) for a given any two integers, calculate the number of the two greatest common divisor, and the number 3 output;
In the main () method, the implementation of the above three methods of the call,

CodePudding user response:

(1)
Int sum=0;
For (int I=3; I & lt; 100; I + +==3) sum I;
Console. WriteLine (sum);
Other you want to,

CodePudding user response:

 

The static void Main (string [] args)
{
Sum3Number ();
Calculator1 (5, 6);
Calculator2 (20, 30);
}

///& lt; summary>
///multiple of 3 sum
///& lt;/summary>
///& lt; Returns>
Private static int Sum3Number ()
{
Var sum=0;
For (int I=1; I & lt;=100; I++)
{
If (I % 3==0)
{
The sum +=I;
}
}
Return the sum.
}

///& lt; summary>
///computing LCD
///& lt;/summary>
///& lt; Param name="a" & gt;
///& lt; Param name="b" & gt;
Private static void Calculator1 (int a, int b)
{
If (a==0 | | b==0)
{
return;
}
Int minValue=https://bbs.csdn.net/topics/1;
While (true)
{
If (a==minValue % 0 & amp; & MinValue % b==0)
{
break;
}
MinValue++;
}
Console. WriteLine (the string. Format (" input value is {0} and {1}, LCM is {2} ", a, b, minValue));
}

///& lt; summary>
///the greatest common divisor
///& lt;/summary>
///& lt; Param name="a" & gt;
///& lt; Param name="b" & gt;
Private static void Calculator2 (int a, int b)
{
If (a==0 & amp; & B==0)
{
return;
}
Int maxValue=https://bbs.csdn.net/topics/1;
Int tem=1;
While (true)
{
If (a % tem==0 & amp; & B % tem==0)
{
MaxValue=https://bbs.csdn.net/topics/tem;
}

If (tem & gt;=a | | tem & gt;=b)
{
break;
}
Tem++;
}
Console. WriteLine (the string. Format (" input value is {0} and {1}, greatest common divisor is {2} ", a, b, maxValue));
}

CodePudding user response:

Suggest that we don't directly to the source code.

CodePudding user response:

Basic logic and the greatest common divisor and least common multiple, or only one of, or don't know, suggest to check first

CodePudding user response:

Code is very simple, give you a idea

Greatest common divisor: with the input of the two Numbers a and b, respectively, to remove a number of c, c values is the key of c is greater than or equal to a small value of b, less than or equal to a large value of b, so c to great value from the beginning, then let a and b, c - for the first time can let a and b to the whole number c is the greatest common divisor of

LCM: in the same way for c, take a large value of b, c and to respectively divided by a, b, c every c + +, until you find the first can the values of a and b, c is the least common multiple

CodePudding user response:

reference 5 floor verve ling day reply:
code is very simple, give you a way of thinking

Greatest common divisor: with the input of the two Numbers a and b, respectively, to remove a number of c, c values is the key of c is greater than or equal to a small value of b, less than or equal to a large value of b, so c to great value from the beginning, then let a and b, c - for the first time can let a and b to the whole number c is the greatest common divisor of

LCM: in the same way for c, take a large value of b, c and to respectively divided by a, b, c every c + +, until you find the first can the values of a and b, c is the least common multiple of

I want to know in a different methods defined in a class is what mean

CodePudding user response:

refer to 6th floor qq_45734799 response:
Quote: refer to fifth floor verve ling day response:
code is very simple, give you a way of thinking

Greatest common divisor: with the input of the two Numbers a and b, respectively, to remove a number of c, c values is the key of c is greater than or equal to a small value of b, less than or equal to a large value of b, so c to great value from the beginning, then let a and b, c - for the first time can let a and b to the whole number c is the greatest common divisor of

LCM: in the same way for c, take a large value of b, c and to respectively divided by a, b, c every c + +, until you find the first can the values of a and b, c is the least common multiple of

I want to know in a different methods defined in a class is what mean ah


Public class A
{
Public methods (1)
{}

Public methods (2)
{}

.
}


  •  Tags:  
  • C#
  • Related