0% found this document useful (0 votes)
4 views8 pages

Son

The document contains various C programming code snippets for generating different types of triangles and shapes using characters. It includes solid and hollow triangles, rhombuses, and Pascal's triangle, along with examples of how to input height and print patterns. Additionally, there is a section that generates a triangle of prime numbers based on user input.

Uploaded by

eddiestran2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Son

The document contains various C programming code snippets for generating different types of triangles and shapes using characters. It includes solid and hollow triangles, rhombuses, and Pascal's triangle, along with examples of how to input height and print patterns. Additionally, there is a section that generates a triangle of prime numbers based on user input.

Uploaded by

eddiestran2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

// bai 1: tam giac vuong can dac

// vuong can ben phai


//#include <stdio.h>
//main() {
// int h,i,j;
// printf("nhap chieu cao: ");
// scanf("%d", &h);
// for (i = 1; i <= h; i++) {
// for (j = h; j > i; j--) {
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// printf("# ");
// }
// printf("\n");
// }
//}

// vuong can dac trai


//#include <stdio.h>
//int main() {
// int h,i,j;
// printf("nhap chieu cao: ");
// scanf("%d", &h);
// for (i = 1; i <= h; i++) {
// for (j = h; j < i; j++) {
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// printf("# ");
// }
// printf("\n");
// }
//
// return 0;
//}

//vuong can dac tren ben trai


//#include <stdio.h>
//int main() {
// int h,i,j;
// printf("nhap chieu cao: ");
// scanf("%d", &h);
// for (i = h; i >= 1; i--) {
// for (j = h; j > i; j--){
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// printf("# ");
// }
// printf("\n");
// }
//
// return 0;
//}

//vuong can dac tren ben phai


//#include <stdio.h>
//int main() {
// int h,i,j;
// printf("nhap chieu cao: ");
// scanf("%d", &h);
// for (i = h; i >= 1; i--) {
// for (j = h; j < i; j++){
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// printf("# ");
// }
// printf("\n");
// }
//
// return 0;
//}
// tam giac rong trai
//#include <stdio.h>
//
//int main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
//
// for (i = 1; i <= h; i++) {
// for (j = h; j > i; j--) {
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// if (j == 1 || j == i || i == h) {
// printf("# ");
// } else {
// printf(" ");
// }
// }
// printf("\n");
// }
//
// return 0;
//}

//tam giac rong phai


//#include <stdio.h>
//main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
//
// for (i = 1; i <= h; i++) {
//
// for (j = 1; j <= i; j++) {
// if (j == 1 || j == i || i == h) {
// printf("# ");
// } else {
// printf(" ");
// }
// }
// for (j = h; j > i; j--) {
// printf(" ");
// }
// printf("\n");
// }
//}

// tam giac rong duoi phai


//#include <stdio.h>
//
//main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
// for (i = h; i >= 1; i--) {
// for (j = h; j > i; j--) {
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// if (j == 1 || j == i || i == h) {
// printf("# ");
// } else {
// printf(" ");
// }
// }
// printf("\n");
// }
//}

// tam giac rong duoi trai


//#include <stdio.h>
//main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
// for (i = h; i >= 1; i--) {
// for (j = 1; j <= i; j++) {
// if (j == 1 || j == i || i == h) {
// printf("# ");
// } else {
// printf(" ");
// }
// }
//
// printf("\n");
// }
//}

//bai 2
// hinh thoi (j)
//#include <stdio.h>
//main() {
// int i, j, n;
// printf("Nhap n: ");
// scanf("%d", &n);
// for (i = 1; i <= n; i++) {
// for (j = i; j < n; j++) {
// printf(" ");
// }
// for (j = 1; j <= (2 * i - 1); j++) {
// printf("#");
// }
// printf("\n");
// }
// for (i = n - 1; i >= 1; i--) {
// for (j = n; j > i; j--) {
// printf(" ");
// }
// for (j = 1; j <= (2 * i - 1); j++) {
// printf("#");
// }
// printf("\n");
// }
//}

//tam giac can duoi (l)


//#include <stdio.h>
//main()
//{
// int i, j, n;
// printf("Nhap n: ");
// scanf("%d", &n);
// for (i = n ; i >= 1; i--)
// {
// for (j = n; j > i; j--)
// {
// printf(" ");
// }
// for (j = 1; j <= (2 * i - 1); j++)
// {
// printf("* ");
// }
// printf("\n");
// }
//}

// hình m
//#include <stdio.h>
//
//int main() {
// int h,i,j;
// printf ("nhap chieu cao: ");
// scanf ("%d", &h);
// for (i = 1; i <= h; i++) {
// for (j = 1; j <= i; j++) {
// printf("%d ", j);
// }
// printf("\n");
// }
// return 0;
//}

//mau n
//#include <stdio.h>
//
//int main() {
// int h,i,j, space;
// printf ("nhap chieu cao: ");
// scanf ("%d", &h);
// for (i = 1; i <= h; i++) {
// for (space = 0; space < i - 1; space++) {
// printf(" ");
// }
// for (int j = 1; j <= h - i + 1; j++) {
// printf("%d ", j);
// }
// printf("\n");
// }
// return 0;
//}

// mau o
//#include <stdio.h>
//main() {
// int n,i,space,j;
// printf("Nhap n: ");
// scanf("%d", &n);
// for (int i = n; i >= 1; i--) {
// for (int space = 0; space < i - 1; space++) {
// printf(" ");
// }
// for (int j = 1; j <= n - i + 1; j++) {
// printf("%d ", j);
// }
// printf("\n");
// }
//}

// mau p
//#include <stdio.h>
//
//int main() {
// int h,i,j;
// printf ("nhap chieu cao: ");
// scanf ("%d", &h);
// for (int i = 1; i <= h; i++) {
// for (int j = h - i + 1; j >= 1; j--) {
// printf("%d ", j);
// }
// printf("\n");
// }
// return 0;
//}

// mau q
//#include <stdio.h>
//main()
//{
// int i, j, k, n;
// printf("Nhap n: ");
// scanf("%d", &n);
// for (i = 1; i <= n; i++) {
// for (j = 1; j <= n - i; j++)
// printf(" ");
// for (j = 1; j <= i; j++)
// printf("%d ", j);
// for (j = i - 1; j >= 1; j--)
// printf("%d ", j);
// printf("\n");
// }
//}

//mau r
//#include <stdio.h>
//main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
// for (i = h; i >= 1; i--) {
// for (j = 0; j < h - i; j++) {
// printf(" ");
// }
// for (j = 1; j <= i; j++) {
// printf("%2d ", j);
// }
// for (j = i - 1; j >= 1; j--) {
// printf("%2d ", j);
// }
// printf("\n");
// }
//}

// mau s

// mau t

//mau u
//#include <stdio.h>
//main()
//{
// int n;
// int i, j, k, num;
// printf("Nhap n: ");
// scanf("%d", &n);
// for (i = 1; i <= n; i++)
// {
// for (j = n; j > i; j--)
// {
// printf(" ");
// }
// num = i;
// for (k = 1; k <= i; k++)
// {
// printf("%d ", num++);
// }
// num -= 2;
// for (k = 1; k < i; k++)
// {
// printf("%d ", num--);
// }
// printf("\n");
// }
//}
//Triangle
//(a) PowerOf2Triangle
//#include <stdio.h>
//main() {
// int h, i, j;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
// for (i = 0; i < h; i++) {
// for (j = 0; j < h - i - 1; j++) {
// printf(" ");
// }
// int num = 1;
// for (j = 0; j <= i; j++) {
// printf("%4d", num);
// num *= 2;
// }
// num /= 2;
// for (j = i - 1; j >= 0; j--) {
// num /= 2;
// printf("%4d", num);
// }
// printf("\n");
// }
//}

//(b) PascalTriangle1
//#include <stdio.h>
//main() {
// int h, i, j, coef;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
//
// for (i = 0; i < h; i++) {
// coef = 1;
// for (j = 0; j <= i; j++) {
// printf("%3d", coef);
// coef = coef * (i - j) / (j + 1);
// }
// printf("\n");
// }
//}

//(c) PascalTriangle2
//#include <stdio.h>
//main() {
// int h, i, j, coef;
// printf("Nhap chieu cao: ");
// scanf("%d", &h);
// for (i = 0; i < h; i++) {
// for (j = 0; j < h - i; j++) {
// printf(" ");
// }
// coef = 1;
// for (j = 0; j <= i; j++) {
// printf("%6d", coef);
// coef = coef * (i - j) / (j + 1);
// }
// printf("\n");
// }
//}

//bai 3
//Đề thi 2021: nhap n, in ra tam giac co chieu cao với số dòng bang n, cac gia tri
tại các điểm la SNT.
//Ví dụ khi khai n=8 ta có hình.
//#include <stdio.h>
//int main() {
// int n;
// printf("Nhap n: ");
// scanf("%d", &n);
// int count = 0, num = 2;
// for (int i = 1; i <= n; i++) {
// int printed = 0;
// while (printed < i) {
// int isPrime = 1;
// for (int j = 2; j * j <= num; j++) {
// if (num % j == 0) {
// isPrime = 0;
// break;
// }
// }
// if (isPrime) {
// printf("%d ", num);
// printed++;
// }
// num++;
// }
// printf("\n");
// return 0;
//}

You might also like