Saturday, June 20, 2015
[Programming book CHAPTER FIVE] a little math.
In this chapter we are not going to learn anything new programing. So far we have learned so much programming, with what will solve some simple math problems.
1) x + y = 15, x - y = 5, when the value of x and y-?
Samikaranaduti if we get 2x = 20, or x = 10. Again minus the pie, 2y = 10, or y = 5. Now write a program where x + y and x - y-'s value will be paid, x, and you need to find the value of y-. A little later I'll write the program. Try yourself in writing. Easy program.
Ii) 4x + 5y = 14, 5x + 6y = 17 What is the value of the x and y-?
Samikaranadutike we can write this:
a1x + b1y = c1, a2x + b2y = c2. You have several ways to resolve it. There are two popular ways of getting replacement (substitution) and criteria (determinant) of the solution. If you do not know the methods Class Eight or Nine books on mathematics. If the solution will look,
x = (b2c1 - b1c2) / (a1b2 - a2b1) and y = (a1c2 - a2c1) / (a1b2 - a2b1). Now, a1, a2, b1, b2, c1, c2- of putting in place enough value to get the value of x and y-.
We will write a program to solve the equation of this kind, which will be input a1, a2, b1, b2, c1, c2, and will output the value of x and y-. It is also easy to program. Try it yourself.
Hopefully, you will have to manually resolve the problems.
The solution is simple. Notice that I use int data type of the variable does not have to use double.
The program's simple! Then on (a1 * b2 - a2 * b1) - Twice I found out the value of (x- to the value of time, to get the value of the y-). And at once it would have been better off if, then our program will lower the quality of work and a minus. Again (a1 * b2 - a2 * b1) - If the value is zero, it's going to be a disturbance, because it is something that can not be divided by zero. So if the value is zero, the equation has no solution. I wrote the program better.
Here as a concern. I wrote out of if- (int) d == 0. I was here first d (which is a double-type variable) to integer type, its value is equal to 0, then the cast did not have to test it. The trial was thus: if (d == 0.0), but sometimes it is wrong, for floating point calculations. You will understand that the education of computer architecture.
This is a question that may come to your mind to solve problems What is programming? Once the program after the fact, but the solution is not to write. Only then will the input, the output of the program will give you the answer in itself.
3) If I give you ten thousand rupees loan interest rate to 35% and the five-year period, the money to pay you interest-actually say, then how much money you have to pay a total of five years and how much you will pay per month? Rnata if something is not complicated, then you will have to pay a total of 10000 + 10000 * 35/100. This simple, let's write a program for a loan.
Pharmulate we have a little problem. In fact, the annual interest on the interest rate will be 35%. 35% interest on the total debt to be paid every year. So in five years, you will have to pay a total of 10000 + 10000 * 35 * 5/100. Now, according to this formula, put down the program.
But the reality is not so simple, however, credit the accounts. You will feel it when you take out a loan from the bank.
4) Let's solve a problem of physics.
U No matter adibege (initial velocity) and a tbarane (acceleration) The journey started (the value of the acceleration a will, does not increase or decrease). Time after time t v is the velocity of the object at the time how much distance will not exceed 2t? (Shahriar has granted problem, it is problem number bhyaladalida online Bodhidharma 10071).
2t will march at vx 2t. Even if it proved. And then start to fall again. Ninth-class physics book, you will have two sources:
v = u + at
s = ut + 0.5 at ^ 2 (t here is s the march).
2t, then the time will be after the march
ux 2t + 0.5 xax (2t) ^ 2 = ux 2t + 0.5 xax 4t ^ 2 = ux 2t + ax 2t ^ 2 = 2t (u + at) = 2tv
Now, you have to write a program, which will be given as input to the value of v and t-, 2t at the time of determining the distance to be crossed. Fellow entering the program itself.
5) 1 + 2 + 3 + ... + 998 + 999 + 1000 how much of this sum?
You know the sum of the section, they will be able to say, offhand, the sum of this series is 1000 x 1001/2. Let's write a program for you, at the end, the value of the sum of the input and output.
If you do not know the formula used to determine the sum of the loop section, we can write the program.
So do not worry about the problem section. If you have a position that is growing much more than the value of its previous position, it can get, then you will be out of the loop by using the sum. If we can find the source of the loop, do not use. First on the program (where the formula used). There is added, a quality that has a share, n-, no matter the value as much. The second program (where the loop used) n- as the standard, has been added to many times, and the sum of the sum has to be a variable (but keep the value of any variable, it takes a little time).
Now you have to write a simple program. N is an odd number is the sum of the first positive diagnosis program. n- of the value of the input, the output will be the sum.
6) We will ebarakara program Celsius (Celsius) to Fahrenheit (Farenheit) conversion program.
Selasiyasake Fahrenheit conversion formula is: ° F = (° C × 1.8) + 32.
Celsius to Fahrenheit conversion programs are now being written in your job.
7) Now, we have two numbers gasagu (GCD → Greatest Common Divisor or HCF → Highest Common Factor) and lasagu (LCM → Least Common Multiple) to evaluate the program type.
Gasagu two numbers are the numbers, which divides the two numbers that, among the large number of them. Which then we'll take the two numbers a and b. And which of these are small, the value of the x variable will again. Gasagu can not be greater than the value of the x- (5 and 10 gasagu values must not be greater than 5). Now, a and b, x is not what divides with (a% x == 0 and b% x == 0), it'll check. If so, we've got gasagu. If both a and b are not divides, will try to reduce the value of the x-. Until we can gasagu will avoid the value of x-. Once we pabai gasagu, while the x- value of 1, then x is the number divides both a and b. Would you try to write programs.
Gcd to get on the program will be out of the loop (I've used this to break). What happens if you do not use break on the test.
However, the methods I've used to get gasagu very simple procedure, but it iphisiyenta (efficient) is not. For example, if two very large numbers and sahamaulika (co-prime), but many times when you turn lupati. If the sahamaulika will gasagu 1. Surely you know that the common divisor of two numbers between 1 if there is no number two sahamaulika.
There is a nice way to get gasagu Euclid. Euclid remainder theorem (division algorithm) showed the way to find the gasagu. In this manner it is possible to very easily gasagu and the program is quite iphisiyenta. It will take two things to know:
gasagu the value of a and 0 a.
and b- gasagu of a = b and a% b-'s gasagu.
If the program to which a loop of the a- and b- values of b value will be putting a% b, b- until the value is zero. b- gasagu that will determine if the value of zero being a (it is not, but the program start time, the value of a-, b- a- of the value of the value will be zero).
This program will also try to iphisiyenta.
Lasagu to the program. Surely you have learned in school, to find out how lasagu. Fellow of the method of entering the program. And those who do not know the method, they would be a formula. Hopefully, they will be able to write programs to lasagu.
Lasagu x = number between two numbers gasagu product of the two numbers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment