*Kiểu giữ liệu: kiểu dữ liệu thường được khai báo bằng int, float,double, char
-Những kiểu khai báo này được dùng kể khai báo tất cả những kiểu dữ liệu được nhập vào như
int dùng đề khai báo kiểu số nguyên.,float , double : dùng để khái báo kiểu số thực..char: dùng để khai báo kiểu ký tự.
-Vì lí do thừa thiếu không gian chứa giữ liệu người ta đã thêm những lệnh dùng để hạn chế nguồn dữ liệu như short và long:
+ short: sẽ chia một nửa kiểu số nguyên.
+ long: sẽ gấp đôi lên.
*Biến : lưu giá trị của hằng số..trong lập trình biến là nơi nào đó trong bộ nhớ được đánh địa chỉ có kích thước và có giá trị hoặc không
Cách sử dụng : khai báo biến : là lệnh ( Statement;)
vd : int a;
int b;
int : từ khóa
a,b : định danh
II.Bài Tập
Bài 1 :Write a program display your information, for instance:Full-Name, Age, Address
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { printf("Full-Name : Nguyen Trong Huy"); printf("\nAge : 19"); printf("\nAddress : Luong Son-Hoa Binh"); return 0; }
Bài 2: Write a program that accepts a number and square the number
To do this,
a. Accept the number.
b. Multiply the number with itself and display the square
Bài Làm
#include <stdio.h>#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a,S;
printf("Nhap mot so bat ki :");
scanf("%d",&a);
S=a*a;
printf("binh phuong cua %d la %d ",a,S);
return 0;
}
Bài 3: Write a C program that accepts the salary and age from the user and displays the same on the screen as output.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a,b;
printf("Muc luong theo do tuoi");
printf("\nMuc luong :");
scanf("%d",&a);
printf("\nDo tuoi :");
scanf("%d",&b);
return 0;
}



Không có nhận xét nào:
Đăng nhận xét