Monday, October 20, 2014

Reflection 8

I.Exercise
1.Re-code again the example in the clip.
File C:Demo
2.Implement functions to solve problems in reflection array
a.Input an positive integer n that indicated the number of element of array
Input n elements of array
b. Display array has just been inputted

c.Calculate sum of all elements
d.Sum of odd element
e. Average of even elements
f.Average of element at odd index
g. Main
File C;array
III. Propose your own example to pass array as a parameter in a function
Check number division 5
File C:example
IV. Reflection
I have more knowledge about array. Now, I can creat array as a parameter  in function . It is convenient when i code.  I will code shorter, faster and find  mistake when have problem.






Wednesday, October 15, 2014

Assignment 1

1 Cách làm
 Đầu Tiên , chúng ta sẽ tính giá trị Tiền gốc mỗi tháng phải trả , Sau đó , Tính tiền lãi mỗi tháng , Tiếp đến chúng ta  tính Tiền bảo hiềm bắt buộc .
Tiếp đến chúng ta sử dụng các câu lệnh " if else " để chia các trường hợp của Bảo hiểm tín dụng, Gia đình có Công , Lực Lượng Vũ trang, Khoản vay . Ngoài câu lênh "if else" chúng ta có thể dùng câu lệnh " switch" để kiểm tra các truuwongf hợp của Bảo Hiểm tính dụng, Gia đình có công, Lực lượng vũ trang.
2. Bài Làm

File C :assignment




reflection 7

I. Exercise

1. Declare an double array with max 100 elements

2. Input an positive integer n that indicated the number of element of array
3. Input n elements of array

4. Display array has just been inputted
5. Calculate sum of all elements, sum of odd element, average of even elements, average of element at odd index

file C;array

6. Propose my array sample 
Check input value divisible 5.
file C:example
II. Reflection
I know use array , i know forming of array. I think array is very important and convenient. Because we do not  declared the variable a lot of if repeat. We will have less mistake when we code . And program will easy check and short code.
We have two way to declare the variable.For example
int[10];
int[3][3];
Note:
- index may be í the real number , when it will take the integer part of the real number as the array index. 
- When the index beyond the array size, the machine is not an error, but will produce a random value, then the computer will access to an external memory arrays and can disrupt the program.



The End 




Monday, October 6, 2014

reflection 6

I. Bài tập

1. void input(int*n, int*m); – input and check n>0, m>0

file C: input

2. int fun2(int n, int m); Function returns n! + mn if n > 0 and m > 0, otherwise return 0

file C;GT+MU

3. double fun6(int n); Function returns value calculated by formula

file C: Tinh S

4. int fun7(int n, int m);
Function returns the highest prime number < nm


5. int fun8(int n, int m);
Function returns the highest Fibonacci number < nm




II vi du về pointer

VD 1:


file C:vd1
VD 2 :


file C:vd2


VD3

File C:vd3


III.Tổng Kết

           Qua bài này em biết được con trỏ là một biến dùng để chứa địa chỉ. Vì có nhiều kiểu địa chỉ nên cũng có nhiều kiểu con trỏ tương ứng. Con trỏ kiểu int dùng để chứa địa chỉ của biến kiểu int, con trỏ kiểu float dùng để chứa địa chỉ của biến kiểu float…


Cũng như các biến khác, con trỏ phải được khai báo trước khi sử dụng. Việc khai báo biến con trỏ như sau:
Kiểu dữ liệu   *tên con trỏ;

Chú ý:
 Khi con trỏ p chứa địa chỉ của biến x thì ta còn có thể nói là con trỏ p trỏ tới x. Và hai cách viết sau là tương đương
-   x tương đương với *p, khi đó *p được coi là bí danh của biến x
-  &x tương đương với p











The End 

Thanks for Reading


Thursday, October 2, 2014

reflection 6

I. Sự khác nhau giữa biến toàn cục và biến cục bộ.

 1.biến toàn cục được khai báo ở ngoài tất cả các hàm, tất cả các hàm khác đều có thể tham chiếu đến nó ,  có giá trị như nhau đối với tất cả các hàm và chỉ bị hủy khi chương trình kết thúc. 
2. biếm cục bộ được khai báo trong mỗi 1 hàm chỉ có giá trị ở trong hàm khai báo, sang hàm khác nó không còn ý nghĩa.

3. Ví dụ

  Vd 1:
Khi tính biểu thức m *n = s
Khi chúng ta sử dụng biến cục bộ , với mỗi hàm và giá trị của m , n khác nhau sẽ cho ra kết quả s khác nhau.Bởi vì chúng không liên quan đến nhau.

Nhưng khi ta sử dụng biến toàn cục thì kết quả s sẽ là như nhau .
Vd 2:
Hiển thị 1 số n 
biến cục bộ sẽ hiển thị 2 số n khác nhau
biến toàn cục sẽ hiển thị ra 1 số n 
Vd 3:
Tinh tổng S của 2 số cho trước 
Sử dụng biến cục bộ sẽ cho ra 2 tông khác nhau
Sử dụng biến toàn cục sẽ cho ra 2 tổng s giống nhau

II. Sự khác nhau giữa tham trị và tham biến.

1. sự khác nhau

Tham trị là giá trị của tham số.Tham trị là tham số đầu vào. Tham trị viết bình thường.

Tham biến là  tham số dưới dạng tham chiếu và là tham số đầu ra Tham biến khi viết có thêm dấu "&".

2 . Ví dụ

Ví dụ 1
Hoán Đổi giá trị của x, y
Sử dung Tham trị . Ta thấy, sau khi chạy ta thấy giá trị x , y vẫn như ban đầu .
Còn khi sử dụng Tham biến , Giá trị x , y đã được hoán đổi.


Ví Dụ 2
khi cho in 1 giá trị của k .
sử dụng tham trị thấy k =10
sử dụng tham biến ta thấy k = 0

Giải thích;
vì khi truyền tham trị , C sẽ chỉ truyền giá trị của nó hay nói nôm na là truyền bản photocopy. Do vậy, trong hàm nếu có thay đổi giá trị các bản photocopy này thì bản gốc (tức giá trị của tham số ban đầu) vẫn không đụng đậy gì.

 Nhưng khi sử dụng tham biến chương trình không phải truyền giá trị của biến mà là địa chỉ (hay con trỏ) của biến.


Ví Dụ 3
kiểm tra giá trị của x, y , z
Sử dụng tham trị
Sử dụng tham biến .


III. Tổng kết

Qua bài này , em có thể hiểu biết về biến cục bộ và biến toàn cục, tham trị và tham biến . Có thể phân biết giữa các loại với nhau . Chức năng của mỗi loại . Từ đó , có thể tránh không gặp lỗi khi code.





The End 

Thanks for reading







 .




Tuesday, September 30, 2014

reflection 5

I. Summary

1.Function

 In C, It represent a module by a function.
A function may receive data and may return a value.
The description of the internal logic of a function as the function's definition

2. function definition

A function definition consists of a header and a body.  
The body is the code block that contains the module instructions and generates the return value.  
The header, which precedes the body, includes the module name and the list of parameters that receive the module data enclosed within parentheses.  

3. syntax of a function definition


II. Practice

1 .int power(int m, int n) – In: m, n; Out: mn
2.int gt(int n) – In: n; Out: n!
use :
n ! = n*(n-1)*(n-2)*.....*2*1.
3.double expx(double x, double epsi) – In: x, epsi; Out: ex with precision < epsi
use: e^x = 1 + x/1! + x^2/2! + ... + x^n/n!
4.double sinx(double x, double epsi) – In: x, epsi; Out: sin(x) with precision < epsi
use:
sin(x) = x ­ x^3/3! + x^5/5! + ... + (­1)^n*x^(2n+1)/(2n+1)!

5.double pi(double epsi) – In: epsi; Out: PI number with precision < epsi
use: pi = 4*( 1 -1/3+1/5-1/7+....)



6.int highest(double epsi) – In: epsi; Out: Highest n so that 1/n >= epsi


7.int highest1(double epsi) – In: epsi; Out: Highest n so that 1/n! >= epsi

8.int lowest(int m) – In: m; Out: Lowest n so that m < 2n

9. Check n divided 5 
10. calculate sum


III. Total
I know function, i know use function,
I know function is very convenient, we don't must code again. if we need repeat.
we are easy to find problem .


Monday, September 22, 2014

Reflection 4

I.Summary
      I have more knowledge about command "if else" ," switch", " for" in C.
      I know language to communicate with the other programmers by block diagram.

1. if else
It is conditional statement. When Condition is True , It will do work first. When condition is False . It will do work second.
Command if can use several times in the command .
I know block diagram of command "if".






2. switch
Command " switch"  allow option for more work.
"switch" statement  allowed based on the value of an expression to select one of the many different job.
In the syntax of the switch statement, if the job consists of multiple statements, these statements can be placed in a block or can not put in a block.

Note:

Command " switch " always use to check condition. And In many cases, it can not substitute for command " if ".

I know block diagram of command " switch ",

3 . For
Used to create a repeating cycle (loop) have identified some iteration.
For statement include three expressions and body" for". Loop body is a statement
or a block. Any of the three expressions above expressions shall have the right
absent but not lack of semicolons.

Block diagram of command " for"


3 command "if", " switch". " for" are very impotant . It is necessary to we can create.



II. Practice
2 . Calculate  sum of all divisors of n.
The first: I use command "for" to find  divisors of n and show it
the second: Use command "if " to calculate sum


Use command " for " and " if ".
File C:So_n

3.list all digits of n 
use command " while"
let n division 10 and  hold integer portion. the division close when n = 0
 file C:C3

4.List all interger k ( 0 < k < n ) and k % 5 == 0
use command "for" to run k from 0 to n
use command " if " to find k ( k % 5 ==0)
Link C:c4
5. calculate sum S
Use command " for" and apply rules of expression.




II. electric charge
Use command " if" 
With other charge , we will use 1 command "if".
Link C : 
tien dien
III. change shape of star
We will use command " for" .
If you want Gross 4 cases is 1. you can use command " switch" . But if n is very big , we will don't show 4 cases




link c:
sao 1
sao 2
sao 3
sao 4



The End.

Thank for reading.