By GokiSoft.com| 09:39 09/12/2020|
Lập Trình C

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



#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 x, y, s;
	
	printf("\nNhap x = ");
	scanf("%d", &x);
	printf("\nNhap y = ");
	scanf("%d", &y);
	printf("\nNhap x, y = ");
	scanf("%d%d", &x, &y);
	
	s = x + y;
	printf("\nTong s = %d + %d = %d", x, y, s);
	
	float t;
	printf("\nNhap t = ");
	scanf("%f", &t);
	
	char c;
	printf("\nNhap c = ");
	fflush(stdin);fflush(stdout);
	scanf("%c", &c);
	printf("\nc -> %c", c);
	
	//TH dac biet
	//nhap & hien thi char
	printf("\nNhap c = ");
	fflush(stdin);fflush(stdout);
	c = getchar();
	
	putchar(c);
	
	char fullname[50];
	printf("\nNhap ten: ");
	fflush(stdin);fflush(stdout);
	scanf("%s", fullname);
	
	printf("\nfullname = %s", fullname);
	
	/*
	int x, y, s1, s2, s3, s4, s5;
	
	x = 2;
	y = 5;
	
	//Phep toan can ban
	s1 = x + y;//7
	s2 = x - y;//-3
	s3 = x * y;//10
	s4 = x / y;//0.4
	s5 = x % y;//2
	
	//Bieu thuc
	x = x + 2;//x = 4
	//cach 2
	x += 2;//x = 6
	
	//phep tru
	x = x - 5;//x = 1
	x -= 5;//x = -4
	
	//phep nhan
	x = x * 2;
	x *= 2;
	
	//phep chia
	x = x / 2;
	x /= 2;
	
	//phep nhan
	x = x * 2;
	x *= 2;
	
	//phep mode
	x = x % 3;
	x %= 3;
	
	//2 truong hop dac biet vs phep +, -
	x = 5;
	x = x + 1;//x = 6
	x += 1;//x = 7
	x++;//x = 8
	++x;//x = 9
	
	x = x - 1;
	x -= 1;
	x--;
	--x;
	
	//vi du cac TH dac biet
	x = 3;
	printf("\nx = %d", x);
	
	y = x++;
	printf("\nx = %d, y = %d", x, y);//x = 4, y = 3
	
	int t = x++ + ++y + 1;
	//t = 4 (x=5) + 4 (y=4) + 1 => x = 5, y = 4, t = 9
	printf("\nx = %d, y = %d, t = %d", x, y, t);
	
	//x = 5, y = 4, t = 9
	int k = x++ + ++x - --y + 2;
	//k = 5(x=6) + 7(x=7) - 3(y=3) + 2 = 11
	printf("\nx = %d, y = %d, k = %d", x, y, k);//x = 7, y = 3, k = 10 : x = 7, y = 3, k = 11
	*/
	return 0;
}




Tags:

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

5

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