By GokiSoft.com| 15:32 11/09/2020|
Lập Trình C

[Share Code] Tìm hiểu về toán tử & biểu thức logic + scanf & printf + if else trong C - Lập trình C



- Lý thuyết : thi trên cổng portal của ấn độ
- Thực hành
- Assignment
	- Lượng bài tập hoàn thiện trong quá trình học : 50%
	- Bài tập lớn : 50% => buổi 6 => đẩy bài tập

=========================================================
Phần 1: Chữa bài tập & giải đáp thắc mắc
Phần 2:
 	- Biểu thức & toán tử trong lập trình C
 	- Printf/scanf & getchar/putchar
 	- Mệnh đề điều kiện





#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[]) {
	//bat dau code
	//Khai bao bien mo rong.
	int x1, x2, x3;
	int y1 = 5, y2= 7, y3= 9;
	int t1,t2,t3;
	t1= t2= t3 = 7;
	
	//Toan tu trong lap trinh C
	int x = 5;
	x = x + 5;//x = 10
	x = x - 7;//x = 3
	x = x/3;//x = 1
	x = x * 5;//x = 5
	
	x = x % 2;//x = 1 => % => MOD (Chia lay du) -> 5 chia 2 lay du = 1
	
	//Toan tu +-*/% => su dung viet tat
	x = 2;
	x = x + 5;
	x += 5; //+= => = x + => x = x + 5
	
	x = x - 3;
	x -= 3;
	
	x = x/5;
	x /= 5;
	
	x = x * 7;
	x *= 7;
	
	x = x%3;
	x %= 3;
	
	//Toan tu +- => voi truong hop dac biet
	x = x + 1;
	x += 1;
	x++; //Tim hieu su khac nhau cua x++ va ++x
	++x;
	
	x = x - 1;
	x -= 1;
	x--; //Tim hieu su khac nhau cua x-- va --x
	--x;
	
	//Tim hieu su khac nhau cua x++ va ++x
	//x++ => gan gia tri sau do moi thay doi gia tri
	//++x => thay doi gia tri xong moi gan
	x = 5;
	int y = x++;
	//ket qua nay x = ?, y = ?
	printf("\nx=%d, y=%d", x, y);//x = 6, y = 5;
	
	//t = (x=7) 7 + 7 (x = 8) - (y=4) 4, t = 10
	int t = (++x) - --y  + (x++);
	//ket qua x = ?, y = ?, t = ?
	printf("\nx=%d, y=%d, t=%d",x, y, t);
	//t=10,x=8,y=4
	
	//k = (x=9) 9 + 1 - (t=9) 9 + 5 + 4 (y=5) + 9 (t = 10) = 19 
	int k = ++x + 1 - --t + 5 + y++ + t++;
	//x=?, y=?, t=?, k=?
	printf("\nx=%d,y=%d,t=%d,k=%d",x,y,t,k);
	
	
	
	//ket thuc code
	return 0;
}



#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[]) {
	//bat dau code
	int x, y;
	printf("\nNhap x = ");
	scanf("%d", &x);
	
	printf("\nNhap x = ");
	scanf("%d", &x);
	
	printf("\nNhap x, y: ");
	scanf("%d%d", &x, &y);
	
	fflush(stdin);fflush(stdout);
	char c;
	printf("\nNhap c = ");
	scanf("%c", &c);
	
	fflush(stdin);fflush(stdout);
	printf("\nNhap c = ");
	c = getchar();//danh cho char
	
	printf("\n%c", c);
	putchar(c);//danh cho char
	
	char str[5];//chuoi str => co do dai max = 5
	printf("Nhap chuoi str = ");
	scanf("%s", str);
	
	printf("Str = %s", str);
	
	
	
	
	//ket thuc code
	return 0;
}



#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[]) {
	//bat dau code
	float a, b, x;
	
	printf("\nNhap a = ");
	scanf("%d", &a);
	printf("\nNhap b = ");
	scanf("%d", &b);
	
	if(a == 0) {
		//TH: D
//		printf("\nTH a = 0");
		if(b == 0) {
			//TH D
			printf("\nPTVSN");
		} else {
			//TH S
			printf("\nPTVN");
		}
	} else {
		//TH: S
		x = -b/a;
		printf("\nNghiem x = %f", x);
	}
	
	//ket thuc code
	return 0;
}






Tags:

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)