Bài 1: #include<stdio.h> #include<conio.h> void main() { int a,b,i,j; printf("nhap vao canh a,b:"); scanf("%d%d",&a,&b); { for(i=1;i<=a;i++) { for(j=1;j<=b;j++) printf("*"); printf("\n"); } } getch(); } //ve hinh chu nhat Bài 2: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int n; printf("nhap vao n:"); scanf("%d",&n); int i=0; int tong=0; while(i<=n) tong = tong + pow(2,i); i++; printf("tong la:%f",tong); getch(); } //tinh tong 2^0+2^1+2^2+ +2^n Bài 3: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int n; printf("nhap vao n:"); scanf("%d",&n); int i=0; int s=0; while(i<=n) { s = s + pow(2,i); i=i+1; } printf("tong la:%d",s); getch(); } //tinh tong 2^0+2^1+ +2^n Bài 4: #include<stdio.h> #include<conio.h> void main() { //int n; int i; printf("nhap vao nam:"); //scanf("%d",&n); scanf("%d",&i); { /*for(i=1;i<=n;i++)*/ if(i%4==0 && i%100==0 || i % 400 != 0) printf("\n so nam nhuan la:%d",i); } getch(); } Bài 5: #include<stdio.h> #include<conio.h> void main() { printf("bamg cua chuong"); int i=1; int j=1; { for(i=1;i<=10;i++) { for(j=1;j<=10;j++) printf("\n %d * %d = %d",i,j,i*j); } } getch(); } Bài 6: #include<stdio.h> #include<conio.h> void main() { int thang; printf("nhap vao thang:"); scanf("%d",&thang); switch(thang){ case 4: case 6: case 9: case 11:printf("co 30 ngay");break; case 1: case 3: case 5: case 7: case 8: case 10: case 12:printf("co 31 ngay");break; case 2: if (100%4==0) printf("co 29 ngay"); else printf("co 28 ngay"); default:printf("nhap sai");} getch(); } Bài 7: #include<stdio.h> #include<conio.h> void main() { int n; printf("nhap vao gia tri:"); scanf("%d",&n); int i=1; int s=0; { s=s+(1/i); i++; } printf("tong la:%d",s); getch(); } Bài 8: #include<stdio.h> #include<conio.h> void main() { int n; printf("nhap vao gia tri n:"); scanf("%d",&n); int i=1; int dem=0; while (i<=n) { n%i==0; dem=dem+i; i++; } printf("tong tat ca cac uoc cua n la:%d",dem); getch(); } Bài 9: #include<stdio.h> #include<conio.h> void main() { int n; printf("\n nhap vao gia tri n:"); scanf("%d",&n); int i=1; int s=0; while (i<=n) { s=s+i*i; i++; } printf("\n tong la:%d",s); getch(); } //bài 2 tinh s=1^2+2^2+3^2+ +n^2 Bài 10: bai 1:tinh s=1+2+3+ +n #include<stdio.h> #include<conio.h> void main() { int n; printf("\n nhap vao gia tri n:"); scanf("%d",&n); int i=1; int s=0; while (i<=n) { s = s + i; i++; } printf("\n tong la:%d",s); getch(); } Bài 11: #include<iostream.h> #include<stdio.h> #include<conio.h> #include<math.h> void main() { int a,b,c; float denta,x1,x2; printf("\n nhap vao a,b,c:"); scanf("%d%d%d",&a,&b,&c); //float denta,x1,x2; denta=(float)(b*b)-(4*a*c); if (denta<0) printf("phuong trinh vo nghiem"); else if (denta==0) { int x=-b/2*a; printf("phuong trinh co nghiem kepla :x1=x2=%.2f",x); } else { x1=-b-(sqrt(denta))/(2*a); x2=-b+(sqrt(denta))/(2*a); printf("phuong trinh co nghiem la:"); printf("\n x1=%f",x1); printf("\n x2=%f",x2); } getch(); } //phuong trinh bac hai Bài 12: //nhap vao ba canh xet xem co phai tam giac thuong ,vuong,vuong can,can,deu #include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("nhap vao ba canh:"); scanf("%d%d%d",&a,&b,&c); if(a+b<=c||a+c<=b||b+c<=a) printf("khong phai la tam giac"); else if(a==b||b==c) printf("la tam giac deu"); else if(a==b||b==c||a==c) printf("la tam giac can"); else if (a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a) printf("la tam giac vuong"); else if(a==b||a==c||b==c) printf("la tam giac vong can"); else //(a+b>c||a+c>b||b+c>a) printf("la tam giac thuong"); getch(); } Bài 13: //tinh tong s=1^3+2^3+ +n^3 #include<stdio.h> #include<conio.h> void main() int n; printf("\n nhap vao gia tri n:"); scanf("%d",&n); int i=1; int s=0; while(i<=n) { s=s+i*i*i; i=i+1; } printf("\n tong la:%d",s); getch(); } Bài 14: //nhap diem de xem xep loai gi.neu tu 0 den 3 thi yeu,4 kem,5,6thi tb,7,8 kha,9,10 gioi; #include<stdio.h> #include<conio.h> main() { char diem; printf("nhap diem cua ban:"); scanf("%d",&diem); switch (diem) { case 0: case 1: case 2: case 3:printf("kem");break; case 4:printf("yeu");break; case 5: case 6:printf("trung binh");break; case 7: case 8:printf("kha");break; case 9: case 10:printf("gioi");break; default:printf("nhap sai"); } } Bài 15: #include<stdio.h> #include<conio.h> void main() { int n; int s; int i; s=0; i=0; printf("nhap vao gia tri n:"); scanf("%d",&n); while (i<=n) { s=s+i; i++; } printf("tong la :%d",s); getch(); }//tinh tong n=1+2+3+ +n Bài 16: //su dung ham tinh tong hieu tich thuong cua hai so #include<stdio.h> float sohoc(float,float,char); void main() { int a,b; scanf("%d%d",&a,&b); printf("nhap vao hai so a,b:"); printf("\n tong la:%f",sohoc(a,b,'+')); printf("\n hieu la:%f",sohoc(a,b,'-')); printf("\n tich la:%f",sohoc(a,b,'*')); printf("\n thuong la:%f",sohoc(a,b,'/')); } float sohoc(float x,float y,char tinh) { float kq; switch (tinh) { case '+':kq=x+y;break; case '-':kq=x-y;break; case '*':kq=x*y;break; case '/':kq=x/y;break; } return kq; } Bai 17: #include<conio.h> #include<stdio.h> #include<string.h> #include<ctype.h> void main() { char ten[12],ho[10],*t; printf("nhap vao ten:"); gets(ten); printf("nhap vao ho:"); gets(ho); strcat(ho,ten); printf("Ho va ten:"); puts(ho); getch(); int l=strlen(strcat(ho,ten)); printf("chieu dai chuoi vua nhap la:%d",l); //t=toupper(ten); puts(t); } Bài 18: #include<stdio.h> #include<conio.h> #define pi 3,14 void main() { float r,chuvi,dientich; printf("nhap vao ban kinh duong tron:"); scanf("%f",&r); chuvi=(float)2*(pi)*(r); dientich=(float)(pi)*(r*r); printf("chu vi la:%.2f\n",chuvi); printf("dientichla:%.2f\n",dientich); getch(); } Bài 19: #include<stdio.h> #include<conio.h> /*{ int n; int s; int i; s=0; i=0; printf("nhap vao gia tri n:"); scanf("%d",&n); while (i<=n) { s=s+i; i++; } printf("tong la :%d",s); getch();}*/ //tinh tong n=1+2+3+ +n void main() { int n; printf("nhap vao gia tri n:"); scanf("%d",&n); int kq = TinhTong(n); printf("tong la:%d",kq); getch(); } int TinhTong( int n) { int s=0; for (int i=0;i<=n;i++); s=s+i; . s=0; while (i<=n) { s=s+i*i; i++; } printf(" tong la:%d",s); getch(); } / /bài 2 tinh s=1^2+2^2+3^2+ +n^2 Bài 10: bai 1:tinh s=1+2+3+ +n #include<stdio.h> #include<conio.h> void. a,b:"); scanf("%d%d",&a,&b); { for(i=1;i<=a;i++) { for(j=1;j<=b;j++) printf("*"); printf(" "); } } getch(); } //ve hinh chu nhat Bài 2: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int. + pow(2,i); i++; printf("tong la:%f",tong); getch(); } //tinh tong 2^0+2^1+2^2+ +2^n Bài 3: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int