1. Trang chủ
  2. » Thể loại khác

tai lieu c ppsx

9 244 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 9
Dung lượng 86 KB

Nội dung

Cau1 #include<stdio.h> #include<conio.h> #include<math.h> void main() {float a,b,c,cv,p,s; printf("nhap a,b,c"); scanf("%f%f%f",&a,&b,&c); if ((a+b)>c)//((a+c)>b)//((c+b)>a) &&(a>0)&&(b>0)&&(c>0)) { cv=a+b+c; p=(cv/2); s=sqrt(p*(p-a)*(p-b)*(p-c)); printf("chuvi=%f, dientich=%f",cv,s);} else printf("khong tao thanh tam giac"); getch();} Cau2 #include <stdio.h> #include<conio.h> int a,b,ch; void main() {printf("nhap a va b"); scanf ("%d%d",&a,&b); fflush (stdin); printf("nhappheptinh");scanf("%c",&ch); switch (ch) {case'+' : {printf("%d+%d=%d",a,b,a+b); break; } case '-': {printf("%d-%d=%d",a,b,a-b); break; } case'*' : {printf("%d*%d=%d",a,b,a*b); break; } case'/' : printf("%d/%d=%d",a,b,a/b);} getch();} cau3 #include <stdio.h> cau 21/* In so nguyen to nho hon n */ #include <stdio.h> #include<conio.h> void main() {int n, i, j; printf("\n Nhap gia tri cua N: "); scanf("%d", &n); printf ("\nCac so nguyen to nho hon %d la:",n); for (i=2; i<n; i++) { for (j=2; j<i; j++)if (i%j == 0) break; if (j == i) printf("%d ", i); } getch();} cau22/* Tính can 2 theo nguyên tac Newton */ #include <stdio.h> #include <conio.h> #include <math.h> void main() { double a, e,xn, ketqua; printf("\nNhap vào so muon tính can bac 2: "); scanf("%lf", &a); tt: printf ("nhap e"); scanf ("%lf",&e); if (e>0.0001) goto tt; xn = (a+1)/2; do { ketqua = xn; xn = 0.5 * (xn + a/xn);} while (fabs(xn-ketqua) > e); printf("\n Ket qua = %5.3lf", xn); printf ("\n"); getch(); cau 23 /*So lon nhat trong 5 so*/ #include <stdio.h> #include <conio.h> int max(int a,int b) {int m; if (a>b) m=a; else m=b; return m;} void main() {int a,b,c,d,e,Max; printf (" nhap 5 so"); scanf ("%d%d%d%d%d",&a,&b,&c,&d,&e); Max = max(max(max(max(a,b),c),d),e); printf ("ket qua = %d\n",Max); getch();} cau 24 /*Toi gian phan so bang ham*/ #include <stdio.h> #include <conio.h> #include <conio.h> void main() { int t,n,sn; printf ("nhap thang va nam"); scanf("%d %d",&t,&n); switch(t) {case 4: case 6: case 9: case 11: { sn=30; break;} case 1: case 3: case 5:case 7: case 8: case 10: case 12: {sn=31; break ;} case 2: { if (n%4==0) sn=28; else sn=29;} }printf (" thang %d cua nam %d co %d ngay",t,n,sn); getch();} Cau 4 #include<stdio.h> #include<conio.h> void main() {int n,a,b,c; printf("nhap n");scanf("%d",&n); a=n%10;b=(n/10)%10; c=(n/100)%10; if((a+b+c)/3==0) printf("%d chia het cho 3",n); else printf("%d khog chia het cho 3",n); getch();} cau 5 #include <stdio.h> #include <conio.h> float dkc,dkm,n,tong,tv,tv1,tv2,tv3,tv4,t1,t2,t3,t4,tdm; void main() { clrscr(); printf(" nhap dien ke cu "); scanf("%f",&dkc); printf("\n nhap chi so dien ke moi:"); scanf("%f",&dkm); n=dkm-dkc; if (n<=50) tdm=n*450; else tdm=50*450; if ((n>50)&&(n<=100) ) {tv1=(n-50)*700; t1=50*450+tv1;} else if((n>100)&&(n<=150)) {tv2=(n-100)*1200; t2=50*450+50*700+tv2;} else if ((n>150)&&(n<=250)) {tv3=(n-150)*2000; # include <math.h> /*Ham tinh USCLN*/ int USCLN (int n, int m) { while (n != 0 && m != 0) if (n>m) n =n- m; else m =m- n; if (n == 0) return m; else return n; } int main() { int ts,ms; printf ("nhap tu so "); scanf ("%d",&ts); printf ("nhap mau so"); scanf ("%d",&ms); if (USCLN (ts,ms)>1) printf ("phan so chua toi gian!"); if (USCLN (ts,ms)==1) printf ("phan so da toi gian!"); getch(); } cau 25 /*Kiem tra so có chia het cho 3 khong_ dung ham*/ #include <stdio.h> #include <conio.h> /*Hàm tinh tong cua so n*/ int tong(int so) { int k, t=0; while (so) {k=so%10; t=t+k; so=so/10;} return t;} /*Chuong trình chinh*/ void main() { int n,t; do {printf ("nhap 1 so nguyen duong bat ky: "); scanf ("%d",&n);} while (n<0); t= tong (n); if ((t%3)==0) printf ("%d chia h?t cho 3",n); else printf("%d Khong chia het cho 3",n); getch();} cau 26 #include<stdio.h> #include<conio.h> int ham_mu(int x,int n) {int i,mu=1; for (i=0;i<=n;i++) {if(i==0) mu=1; else mu=mu*x;} return(mu); } int main() { tt: int n,s,i,x; do{printf("nhap so mu n="); scanf("%d",&n); printf("nhap gia tri x="); t3=50*450+50*700+50*1200+tv3;} else if(n>250) {tv4=(n-250)*3000; t4=50*450+50*700+50*1200+100*2000+tv4;} tv=t1+t2+t3+t4+tdm; tong =tv+tdm+1000; printf ("\n so tien phai tra trong dinh muc la %.2f",tdm); printf(" \n so tien phai tra vuot dinh muc la %.2f",tv); printf(" \n tong so tien phai tra la %.2f",tong ); getch() ; } Cau6 #include <stdio.h> #include <conio.h> int m,h,s,a; void main () {printf("nhap gio: phut: giay "); scanf ("%d%d%d",&h,&m,&s); printf("nhap so giay cong them "); scanf ("%d",&a); {s=s+a; m=m+s/60; h=h+m/60;s=s%60;m=m%60; printf("gio moila%d:%d:%d",h,m,s);} getch(); } cau7 #include <stdio.h> #include <conio.h> int sn,t,n; void main() {clrscr(); printf("nhap ngay, thang, nam:" ); scanf("%d%d%d",&sn,&t,&n); switch (t) {case 4:case 6:case 9:case 11: {if (sn<=30) printf(" hop le"); else printf("khong hop le ,thang %d cua nam %d chi co 30 ngay",t,n); break; } case 2: {if (sn%4==0) if(sn<=29) printf("hop le"); else printf("khong hop le ,thang %d cua nam %d chi co 29 ngay",t,n); else if (sn<=28) printf("hop le"); else printf("khong hop le ,thang %d cua nam %d chi co 28 ngay",t,n);break; } scanf("%d",&x);} while(x<0||n<0); s=0; for(i=0;i<=n;i++) s=s+ham_mu(-1,i)*ham_mu(x,i); printf("tong la=%d",s); printf("ban co muon tiep tuc khong C/K?"); int k=getch(); if(k=='c'||k=='C')goto tt; } Cau27 #include<stdio.h> #include<conio.h> int ham_mu(int x,int n) {int i,mu=1; for (i=0;i<=n;i++) {if (i==0) mu=1; else mu=mu*x; } return(mu);} int giai_thua(int n) {int i,gt=1;for (i=0;i<=n;i++) {if(i==0) gt=1; else gt=gt*i;} return (gt);} int main() {tt: int n,i,x; do { printf("nhap so mu n=") scanf("%d",&n); printf("nhap gia tri x="); scanf("%d",&x); } while(x<0||n<0); float s=0; for(i=0;i<=n;i++) s=s+ham_mu(x,i)/giai_thua(i); printf("tong la=%f",s); printf("ban co muon tiep tuc khong C/K?"); getch();} cau 28 #include <conio.h> #include <stdio.h> void main() {int a[50],i, n, j,dem=0, tam; printf("\nnhap n : "); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]);} for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) if (a[j] < a[i]) {tam = a[i]; a[i] = a[j]; a[j] = tam;} case 1:case 3: case 5:case 7:case 8: case 10: case 12: {if (sn<=31) printf(" hop le"); else printf(" khong hop le ,thang %d cua nam %d chi co 31 ngay",t,n); } } getch(); } cau 8 #include<stdio.h> #include <conio.h> void main() { char kt; printf (" nhap ky tu can kiem tra"); scanf ("%c",&kt); if (kt>='A'&&kt<='Z') printf ("Chu Hoa");else if (kt>='a'&&kt<='z') printf ("Chu Thuong"); else if (kt>='0'&& kt<='9') printf ("So");else printf ("Khac"); getch(); } Cau 9 #include <stdio.h> #include <conio.h> int main() { char kt; printf ("\nnhap vao ky tu "); scanf ("%c",&kt); printf ("\n"); if (kt>='0'&&kt<='9') printf (" gia tri trong he DEC = %c",kt); if (kt== 'A') printf ("A(HEX)=10(DEC)"); if (kt== 'B') printf ("B(HEX)=11(DEC) "); if (kt== 'C') printf (" C(HEX)=12(DEC) "); if (kt== 'D') printf (" D(HEX)=13(DEC) "); if (kt== 'E') printf (" E(HEX)=14(DEC) "); if (kt== 'F') printf (" F(HEX)=15(DEC) "); if (kt<'0'|| kt>'9'&&kt<'A'||kt>'F') printf (" khong co kys tu nay trong he HEX "); getch(); } cau 10 #include<stdio.h> #include<conio.h> void main() for (i=0; i<n; i++) printf ("%d ",a[i]); getch();} cau 29 #include <conio.h> #include <stdio.h> void main() {int a[50], i,k,n,j,tam; printf("\nnhap n : "); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]);} for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) if (a[j] < a[i]) {tam = a[i]; a[i] = a[j]; a[j] = tam; } for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(a[i]==a[j]) {for(k=j+1;k<n;k++) a[k-1]=a[k];n ;j ;} for(i=0;i<n;i++) printf("%5d ",a[i]); getch();} cau 30 #include <conio.h> #include <stdio.h> void main() {int a[50], i,s, n, j,dem=0, tam; printf("\n nhap so phan tu n:"); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]); } for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) if (a[j] < a[i]) {tam = a[i];a[i] = a[j]; a[j] = tam;} printf ("s? l?n nh?t là %d",a[n-1]); printf ("s? nh? nh?t là %d ",a[0]); s=0; for (i=0;i<n;i++) s=s+a[i]; printf ("tong cac phan tu=%d ",s); getch();} { int n,i,k; printf ("Nhap so n"); scanf ("%d",&n); printf (" cac so chinh phuong tu 1 den %d la",n); for (i=2;i<=(n/2);i++) {k=i*i; if (k<=n) printf ("%d ",k);} getch(); } Cau 11 #include<stdio.h> #include<conio.h> void main() { int d,m,y,day,month,year; printf (" nhap ngay - thang - nam "); scanf ("%d%d%d",&d,&m,&y); month=m; year=y; { if (m==1||m==3||m==5||m==7||m==8||m==10) { if (d<31)day=d+1; if (d==31) { day=1; month=m+1; year=y; }} if (m==4||m==6||m==9||m==11) { if (d<30)day=d+1; if (d==30) {day=1; month = m+1; year=y; } }if (m==12) { if (d<31)day=d+1; if (d==31) { day=1; month=1; year=y+1;} } if (m==2) { if (y%4==0 && y%100 != 0||y%400 ==0 ) { if (d<29) day=d+1; if (d==29) {day=1; month=3; year=y; } } Else { if (d<28)day=d+1; if (d==28) {day=1; month=3; year=y; }}}} printf ("ngay mai la ngay %d thang %d nam %d ",day,month,year); getch(); } cau 12 /*t?ng S1 S2 S3*/ #include<stdio.h #include<conio.h> void main() {int s1=0,s4=0,s5=0,n,i,s3=0,m=0; float s2=0,k=0,tu,mau; printf ("nhap n"); scanf ("%d",&n); for (i=1;i<=n;i++) {s1=s1+i; cau 31 #include<stdio.h> #include<conio.h> void main() {int n,j,i,tam,x,a[10]; tt: printf ("nhap n= "); scanf ("%d",&n); for (i=0;i<n;i++) {printf ("a[%d]=",i); scanf ("%d",&a[i]); for (j=1;j<=i;j++) if (a[j-1]>a[i]) {printf ("nhap lai \n"); goto tt;} } for (i=0;i<n;i++) printf ("%d ",a[i]); printf ("\n nhap so can chon "); scanf("%d",&a[n]); n++; for (i=0; i<n; i++) for (j=i+1; j<n; j++) if (a[j] < a[i]) {tam = a[i]; a[i] = a[j]; a[j] = tam; } for (i=0;i<n;i++) printf ("%d ",a[i]); getch();} cau 32 #include<conio.h> #include<stdio.h> void Nhap(int a[50][50],int M,int N) {int i,j;for(i=0;i<M;i++) for(j=0; j<N; j++) {printf("nhap phan tu [%d][%d]",i,j); scanf("%d",&a[i][j]);} }void Xuat(int a[50][50], int M, int N) {int i,j; for(i=0;i<M;i++) {for(j=0; j< N; j++) printf("%d ",a[i][j]); printf("\n");} }void main() { int a[50][50],m,n,x,i,j,dem=0; printf ("nhap vao so dong x so cot"); scanf ("%d%d",&m,&n); printf (" Nhap Ma tran A \n");Nhap(a,m,n); printf ("Ma tr?n A\n"); Xuat (a,m,n); printf ("nhap vao so can so sanh!\n"); scanf("%d",&x); for (i=0;i<=m-1;i++) for (j=0;j<=n-1;j++) if (a[i][j]==x) {dem=dem+1; printf ("a{%d][%d]=%d \n",i,j,a[i][j]);} if (dem==0) printf (" khong co phan tu %d trong mong",x); else printf ("co %d phan tu %d trong mong \n",dem,x); getch();} tu=i; mau=i+1; s2=s2+ tu/mau; if (i%2 ==0) s5=s5+i; else s4=s4+i; s3=s5-s4; } printf ("s1= %d \ns2=%f \ns3=%d \n",s1,s2,s3); getch();} cau 13 #include<stdio.h> #include<conio.h> void main() { int a[50],n,i,vt,max,j; printf("nhap so phan tu n "); scanf("%d",&n); printf ("nhap cac phan tu n :\n "); for(i=0;i<n;i++) { printf("a[%d]=",i); scanf("%d",&a[i]);} max=a[0]; j=0; for(i=0;i<n;i++) if(a[i]>max) { max=a[i]; j=i;} printf("phan tu lon nhat la %d o vi tri so %d\n",max,j+1); getch(); } cau 14 #include <stdio.h> #include <conio.h> void main() { int i,dem=0,n; printf ("Nhap n"); scanf("%d",&n); for(i=n; i!=0; i=i/10) dem++; printf("%d la so cac chu so co trong so %d", dem,n); getch();} Cau 15 /*Tim k sao cho 2^k>n_n nhap vào tu bàn phim */ #include<stdio.h> #include<conio.h> void main() cau33 #include<stdio.h> #include<conio.h> void main() {int a[50],i,j,chan,le,n,dem1,dem2; printf("nhap n");scanf("%d",&n) ; printf("nhap gia tri cua phan tu"); for (i=0;i<n;i++) {printf("a[%d]=",i); scanf("%d",&a[i]);} dem1=0 ; for (i=0;i<n;i++) if (a[i]%2==0) {printf("\n %d so chan ",a[i]); dem1++; } printf("\n co %d so chan ",dem1); dem2=0; for (i=0;i<n;i++) if (a[i]%2!=0) {printf("\n %d so le ",a[i]); dem2++;} printf("\nco %d so le ",dem2); getch();} cau34 #include <conio.h> #include <stdio.h> void main() {int a[50],i,n,j,dem=0,tam; printf("\n nhap n : "); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]);} printf ("ca phan tu khi dao "); for (i=n-1;i>=0;i ) printf (" %d ",a[i]); getch();} cau 35 #include<conio.h> #include<stdio.h> void Nhap(int a[50][50],int M,int N) {int i,j;for(i=0;i<M;i++)for(j=0; j<N; j++) {printf("nhap phan tu [%d][%d]",i,j); scanf("%d",&a[i][j]);} }void Xuat(int a[50][50], int M, int N) {int i,j;for(i=0;i<M;i++) {for(j=0; j< N; j++) printf("%d ",a[i][j]);printf("\n"); } }void Cong(int a[50][50],int b[50][50],int M,int N,int c[50] { int s=1,k=0,n; printf ("nhap n"); scanf ("%d",&n); do { s=s*2; k++; } while (s<n); printf ("voi k=%d thi 2^k> %d",k,n); getch(); } cau 16 /*dao nguoc 1 so nguyen */ #include <stdio.h> #include <conio.h> void main() {int a,n; printf ("nhap n= "); scanf("%d",&n); printf ("so dao nguoc cua %d la",n); for(int i=n; i!=0; i/=10) { a=i%10; printf ("%d",a);} getch(); } cau17/*trung binh day so thuc*/ #include<stdio.h> #include<conio.h> void main() {float a[10],s=0,tb ,n; int i; for(i=1;i<10;i++) {printf (" Phan tu thuc %d = ",i); scanf ("%f",&a[i]); s=s+a[i]; if (a[i]==-1) goto tt; if (a[i]<0) {printf (" %f Khong phai so thuc duong!",a[i]); goto end; } } tt: tb=(s+1) / (i-1); printf ("trung binh = %10.3f",tb) ; end: ; getch(); } cau 18/* DIV */ #include<stdio.h> #include <conio.h> int a,b, c,d; void main() {printf("nhap 2 so nguyen ava b"); scanf ("%d%d",&a,&b); d=1; if (a>=b) [50]) {int i,j;for(i=0;i<M;i++) for(j=0; j<N; j++) c[i][j]=a[i][j]+b[i][j];}void main() {int a[50][50],b[50][50],c[50][50],m,n; printf ("Nhap vao so dongxso cot"); scanf ("%d%d",&m,&n); printf ("Nh?p Ma tran A ");Nhap(a,m,n); printf ("Nh?p Ma tran B ");Nhap (b,m,n); printf ("Ma tran A =\n"); Xuat (a,m,n); printf (" Ma tran B =\n"); Xuat (b,m,n); Cong (a,b,m,n,c); printf ("Ma tran tong=\n"); Xuat (c,m,n);getch(); } Cau36 #include<stdio.h> #include<conio.h> void main() {int a[50],i,n,dem=0,x;do {printf (" nhap so phan tu "); scanf ("%d",&n);} while (n<0); for (i=0;i<n;i++) {printf ("a[%d]= ",i); scanf ("%d",&a[i]);} printf (" nhap so can so sanh "); scanf ("%d",&x); for (i=0;i<n;i++) if (a[i]==x) {dem++; printf ("a{%d}= \n",i,a[i]);} printf ("co %d phan tu bang %d ",dem,x); getch();} cau 37 #include <conio.h> #include <stdio.h> void main() {int a[50],i,j,n,dem,min; printf("\n nhap n: "); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]);} min=a[0]; for (i=0;i<n;i++ ) if (min > a[i]) min = a[i]; printf ("phan tu nho nhat la= %d",min); for (j=0;j<a[i]-1;j++) {c=a-b; while (c>=b) {d++;c=c-b;} } if (b>a) {c=b-a; while (c>=a) {d++;c=c-a;}} printf("%d/%d=%d",a,b,d), getch(); } cau 19 #include<stdio.h> #include <conio.h> float t,n,s; void main() {printf ("\n nhap s="); scanf ("%f",&s); n=1;t=0; while (t<=s) {t=t+1; n++; } printf("ta duoc n=%d",n); getch();} cau 20 #include <stdio.h> #include <conio.h> int USCLN (int n, int m) { while (n != 0 && m) if (n>m) n =n- m; else m =m- n; if (n == 0) return m; else return n;} int BSCNN (int n, int m) {return n * m / USCLN(n, m);} void main() {int n, m; printf("\nNhap vào 2 so nguyen duong : "); scanf("%d%d", &n, &m); printf("\nUSCLN cua %d va %d = %d", n, m, USCLN(n,m)); printf("\nBSCNN cua %d va %d = %d", n, m, BSCNN(n,m)); getch();} if( a[i]==min) dem++; printf (" co %3d phan to nho nhat",a[i]); getch();} cau38 #include<conio.h> #include <stdio.h> void main() {int a[50], x,dem=0,n,i; printf ("nhap n"); scanf ("%d",&n); for (i=0;i<n;i++) {printf(" a[%d]= ",i); scanf ("%d",&a[i]); }printf (" X= "); scanf ("%d",&x); for (i=1;i<n;i++) {if ((a[i]% x) == 0) {dem=dem+1; printf ("a[%d]= %d ",i,a[i]);}} printf ("co %d pt chia het cho %d",dem,x); getch();} cau39 #include <stdio.h> void main() {int a[80],i, n, j,dem=0, tam; float tb,max,min; printf("\nnhap n: "); scanf("%d", &n); for (i=0; i<n; i++) {printf("a[%d]: ",i); scanf("%d", &a[i]);} for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) if (a[j] < a[i]) {tam = a[i];a[i] = a[j]; a[j] = tam;} max=a[0];min=a[n-1]; tb=(max+min)/2; printf (" %5f ",tb); getch();} cau40 #include<conio.h> #include <stdio.h> void main() {int a[50],s=0,n,i,h,k;do {printf ("nhap n:"); scanf ("%d",&n);} while (n<2); for (i=0;i<n;i++) {printf(" a[%d]= ",i); scanf ("%d",&a[i]);}tt: {printf ("nhap h,k"); scanf("%d%d",&h,&k);} if (k>h || h>n || k<0) goto tt; for (i=k;i<=h;i++) {s=s+a[i]; printf ("a[%d]=%d ",i,a[i]);} printf (" tong = %d ",s);getch();} . scanf("%d %d",&t,&n); switch(t) {case 4: case 6: case 9: case 11: { sn=30; break;} case 1: case 3: case 5:case 7: case 8: case 10: case 12: {sn=31; break ;} case 2: { if (n%4==0) sn=28; else. la so cac chu so co trong so %d", dem,n); getch();} Cau 15 /*Tim k sao cho 2^k>n_n nhap vào tu bàn phim */ #include<stdio.h> #include<conio.h> void main() cau33 #include<stdio.h> #include<conio.h> void. {c= a-b; while (c& gt;=b) {d++ ;c= c-b;} } if (b>a) {c= b-a; while (c& gt;=a) {d++ ;c= c-a;}} printf("%d/%d=%d",a,b,d), getch(); } cau 19 #include<stdio.h> #include <conio.h> float

Ngày đăng: 14/08/2014, 18:20

Xem thêm

TỪ KHÓA LIÊN QUAN

w