#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<math.h>
int ucln(int a,int b);
int bcnn(int a,int b);
int pstg(int a,int b);
void fibo(int n);
void shfibo(int n);
int snt(int n);
void lksnt(int n);
void ptsnt(int n);
int scp(int m);
int shh(int n);
int bsin(int n,int x);
void caythong(int n);
main()
{int t=1,so,x,y,n,s;
clrscr();
while(t)
{
printf("\n**********************************");
printf("\n* 1:bai uoc so chung lon nhat *");
printf("\n* 2:bai boi so chung nho nhat *");
printf("\n* 3:bai rut gon phan so *");
printf("\n* 4:bai day so fibo *");
printf("\n* 5:bai tim so hang fibo *");
printf("\n* 6:bai so nguyen to *");
printf("\n* 7:bai liet ke so nguyen to *");
printf("\n* 8:bai phan tich so nguyen to *");
printf("\n* 9:bai so chinh phuong *");
printf("\n* 10:bai so hoan hao *");
printf("\n* 11:cay thong noens *");
printf("\n* 12:bai gtgd cua ham sin *");
printf("\n* 13:thoat *");
printf("\n*************************************");
do
{printf("\nnhap so de chon(1:2:3:4:5:6:7:8:9:10:11:12)"); scanf("%d",&so);
}while(so<1||so>12);
switch(so)
{case 1:{printf("\nnhap so nguyen a=");scanf("%d",&x);
printf("\nnhap so nguyen b=");scanf("%d",&y);
printf("\nso %d va so %d co ucln la:%d",x,y,ucln(x,y));
ucln(x,y);
getch();break;
}
case 2:{ printf("\nnhap so nguyen a=");scanf("%d",&x);
printf("\nnhap so nguyen b=");scanf("%d",&y);
printf("\nso %d va so %d co bcnn la:%d",x,y,bcnn(x,y));bcnn(x,y);
getch();break;}
case 3:{printf("\nnhap tu so khac 0=");scanf("%d",&x);
printf("\nnhap mau so khac 0=");scanf("%d",&y);
if(pstg(x,y))printf("\nphan so da toi gian va rut gon=%d",x/y);
else printf("\nphan so duoc rut gon =%d/%d",x/ucln(x,y),y/ucln(x,y));
getch();break;}
case 4:{printf("\nnhap n=");scanf("%d",&n);
printf("\nday so fibo co dang");
fibo;
getch();break;}
case 5:{printf("\nnhap n=");scanf("%d",&n);
printf("\nso hang fibo la:");shfibo;
getch();break;}
case 6:{printf("\nnhap n=");scanf("%d",&n);
if(snt)printf("\nso %d la so nguyen to",n);
else printf("\nso %d ko phai la so nguyen to",n);
getch();break;}
case 7:{printf("\nnhap n=");scanf("%d",&n);
lksnt;printf("\ncac so nguyen to la");
getch();break; }
case 8:{printf("\nnhap n=");scanf("%d",&n);
printf("\nso %d duoc phan tich la:",n);
ptsnt;getch();break;}
case 9:{printf("\nnhap n=");scanf("%d",&n);
if(scp)printf("\nso %d la so chinh phuong",n);
else printf("\nso %d ko phai la so chinh phuong",n);
getch();break;}
case 10:{printf("\nnhap n=");scanf("%d",&n);
if(shh)printf("\nso %d la so hoan hao");
else printf("\nso %d ko la so hoan hao",n);
getch();break;}
case 11:{printf("\nnhap so dong cua cay thong:");scanf("%d",&n);
printf("\nCAY THONG NOENS:");caythong;
getch();break;}
case 12:{printf("\nnhap n=");scanf("%d",&n);
printf("\nnhap x=");scanf("%d",&x);
printf("\ngia tri gan dung cua ham sin=%d",s);bsin(n,x);
getch();break;}
case 13:exit(0);
}}}
int ucln(int a,int b)
{while(a!=b)
{if(a>=b)a-=b;
else b-=a;
}if(a==1)return b;
else return a;}
int bcnn(int a,int b)
{int x,y;
x=a;y=b;
return (x*y/ucln(a,b));
}
int pstg(int a,int b)
{if(ucln(a,b)==1)return 1;
else return 0;}
void fibo(int n)
{int i,a=1,b=1,fibo=0;
for(i=1;i<=n;i++)
{fibo+=a;
printf("\n% d",a);
a=b;
b=fibo;}return;
}
void shfibo(int n)
{int i,a=1,b=1,sum=0;
for(i=1;i<=n;i++)
{sum+=a;
a=b;
b=sum;}
printf("%d",sum);
}
int snt(int n)
{ int i=2;
while((i<=n/2)&&(n%i!=0))i++;
if(i>n/2)return 1;
else return 0;}
void lksnt(int n)
{int m,dem=0;
for(m=2;m<=n;m++)
if(snt(m))
{dem++;
printf("%5d",m);
if(dem%10==0)printf("\n");
}}
void ptsnt(int n)
{int i=2;
while(i<=n)
{if(n%i==0)
{if(n/i==1)printf("%d",i);
else printf("%d x",i);
n/=i;}
else i++;}}
int scp(int m)
{if(sqrt(m)==(int)sqrt(m))return 1;
else return 0;}
int shh(int n)
{int i,tong=0;
for(i=1;i<=n;i++)
if(n%i==0)tong+=i;
if(tong==n)return 1;
else return 0;}
int bsin(int n,int x)
{int k,dau,u,s,c;
u=x;
s=x;dau=-1;
for(k=1;k<=n;k++)
{c=x*x/(2*k+1);
u=u*c;
s=s+dau*u;
dau=-dau;dau,u,s,c;
}return;}
void caythong( int n)
{int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=2*i-1;j++)
{gotoxy(40-i+j,i);
printf("*");}
for(i=1;i<n/2;i++)
{gotoxy(40,n+i);
printf("*");}
}
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<math.h>
int ucln(int a,int b);
int bcnn(int a,int b);
int pstg(int a,int b);
void fibo(int n);
void shfibo(int n);
int snt(int n);
void lksnt(int n);
void ptsnt(int n);
int scp(int m);
int shh(int n);
int bsin(int n,int x);
void caythong(int n);
main()
{int t=1,so,x,y,n,s;
clrscr();
while(t)
{
printf("\n**********************************");
printf("\n* 1:bai uoc so chung lon nhat *");
printf("\n* 2:bai boi so chung nho nhat *");
printf("\n* 3:bai rut gon phan so *");
printf("\n* 4:bai day so fibo *");
printf("\n* 5:bai tim so hang fibo *");
printf("\n* 6:bai so nguyen to *");
printf("\n* 7:bai liet ke so nguyen to *");
printf("\n* 8:bai phan tich so nguyen to *");
printf("\n* 9:bai so chinh phuong *");
printf("\n* 10:bai so hoan hao *");
printf("\n* 11:cay thong noens *");
printf("\n* 12:bai gtgd cua ham sin *");
printf("\n* 13:thoat *");
printf("\n*************************************");
do
{printf("\nnhap so de chon(1:2:3:4:5:6:7:8:9:10:11:12)"); scanf("%d",&so);
}while(so<1||so>12);
switch(so)
{case 1:{printf("\nnhap so nguyen a=");scanf("%d",&x);
printf("\nnhap so nguyen b=");scanf("%d",&y);
printf("\nso %d va so %d co ucln la:%d",x,y,ucln(x,y));
ucln(x,y);
getch();break;
}
case 2:{ printf("\nnhap so nguyen a=");scanf("%d",&x);
printf("\nnhap so nguyen b=");scanf("%d",&y);
printf("\nso %d va so %d co bcnn la:%d",x,y,bcnn(x,y));bcnn(x,y);
getch();break;}
case 3:{printf("\nnhap tu so khac 0=");scanf("%d",&x);
printf("\nnhap mau so khac 0=");scanf("%d",&y);
if(pstg(x,y))printf("\nphan so da toi gian va rut gon=%d",x/y);
else printf("\nphan so duoc rut gon =%d/%d",x/ucln(x,y),y/ucln(x,y));
getch();break;}
case 4:{printf("\nnhap n=");scanf("%d",&n);
printf("\nday so fibo co dang");
fibo;
getch();break;}
case 5:{printf("\nnhap n=");scanf("%d",&n);
printf("\nso hang fibo la:");shfibo;
getch();break;}
case 6:{printf("\nnhap n=");scanf("%d",&n);
if(snt)printf("\nso %d la so nguyen to",n);
else printf("\nso %d ko phai la so nguyen to",n);
getch();break;}
case 7:{printf("\nnhap n=");scanf("%d",&n);
lksnt;printf("\ncac so nguyen to la");
getch();break; }
case 8:{printf("\nnhap n=");scanf("%d",&n);
printf("\nso %d duoc phan tich la:",n);
ptsnt;getch();break;}
case 9:{printf("\nnhap n=");scanf("%d",&n);
if(scp)printf("\nso %d la so chinh phuong",n);
else printf("\nso %d ko phai la so chinh phuong",n);
getch();break;}
case 10:{printf("\nnhap n=");scanf("%d",&n);
if(shh)printf("\nso %d la so hoan hao");
else printf("\nso %d ko la so hoan hao",n);
getch();break;}
case 11:{printf("\nnhap so dong cua cay thong:");scanf("%d",&n);
printf("\nCAY THONG NOENS:");caythong;
getch();break;}
case 12:{printf("\nnhap n=");scanf("%d",&n);
printf("\nnhap x=");scanf("%d",&x);
printf("\ngia tri gan dung cua ham sin=%d",s);bsin(n,x);
getch();break;}
case 13:exit(0);
}}}
int ucln(int a,int b)
{while(a!=b)
{if(a>=b)a-=b;
else b-=a;
}if(a==1)return b;
else return a;}
int bcnn(int a,int b)
{int x,y;
x=a;y=b;
return (x*y/ucln(a,b));
}
int pstg(int a,int b)
{if(ucln(a,b)==1)return 1;
else return 0;}
void fibo(int n)
{int i,a=1,b=1,fibo=0;
for(i=1;i<=n;i++)
{fibo+=a;
printf("\n% d",a);
a=b;
b=fibo;}return;
}
void shfibo(int n)
{int i,a=1,b=1,sum=0;
for(i=1;i<=n;i++)
{sum+=a;
a=b;
b=sum;}
printf("%d",sum);
}
int snt(int n)
{ int i=2;
while((i<=n/2)&&(n%i!=0))i++;
if(i>n/2)return 1;
else return 0;}
void lksnt(int n)
{int m,dem=0;
for(m=2;m<=n;m++)
if(snt(m))
{dem++;
printf("%5d",m);
if(dem%10==0)printf("\n");
}}
void ptsnt(int n)
{int i=2;
while(i<=n)
{if(n%i==0)
{if(n/i==1)printf("%d",i);
else printf("%d x",i);
n/=i;}
else i++;}}
int scp(int m)
{if(sqrt(m)==(int)sqrt(m))return 1;
else return 0;}
int shh(int n)
{int i,tong=0;
for(i=1;i<=n;i++)
if(n%i==0)tong+=i;
if(tong==n)return 1;
else return 0;}
int bsin(int n,int x)
{int k,dau,u,s,c;
u=x;
s=x;dau=-1;
for(k=1;k<=n;k++)
{c=x*x/(2*k+1);
u=u*c;
s=s+dau*u;
dau=-dau;dau,u,s,c;
}return;}
void caythong( int n)
{int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=2*i-1;j++)
{gotoxy(40-i+j,i);
printf("*");}
for(i=1;i<n/2;i++)
{gotoxy(40,n+i);
printf("*");}
}