tin
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<process.h>
void nhapdulieu(int &n,int &k);
long giaithua(long n);
long sotohop(int n,int k);
int ucln(int m,int n);
void nhapps(int &tu,int &mau);
void gianuocps(int &tu,int &mau);
void inps(int tu,int mau);
void main()
{
int n,a,b;
printf("
moi ban chon chuc nang chuong trinh");
printf("
1-tinh so to hop");
printf("
2-gian uoc phan so");
printf("
3-nhan hai so");
printf("
nhap so chuc nang ban chon");
printf("
5-thoat");
if(n==5)
{
exit(0);
}
if(n==1)
{
int n,k;
long c;
nhapdulieu(n,k);
c=sotohop(n,k);
printf("so to hop la %1d",c);
}
if(n==2)
{
int t,m;
nhapps(t,m);
printf("
nhap so toi gian la");
inps(t,m);
}
getch();
}
void nhapdulieu(int &n,int &k)
{
do
{
printf("nhap n vs k");
scanf("%d%d",&n,&k);
}
while(k>=n);
}
long giaithua(long n)
{
long i,gt;
gt=1;
for(i=1;i<=n;i++)
{
gt=gt*i;
}
return gt;
}
long sotohop(int n,int k)
{
long ngt,kgt,nkgt,c;
ngt=giaithua(n);
kgt=giaithua(k);
nkgt=giaithua(n-k);
c=ngt/(kgt*nkgt);
return c;
}
void nhapps(int &tu,int &mau)
{
do
{
printf("nhap tu va mau");
scanf("%d%d",&tu,&mau);
if(mau==0)
printf("nhap lai");
}
while(mau==0);
}
void inps(int tu,int mau)
{
if(tu==0)
printf("0");
else
if(mau==1)
printf("%d",tu);
else
printf("%d%d",tu,mau);
}
int ucln(int m,int n)
{
while(m!=n)
{
if(m>n)
m=m-n;
else
n=n-m;
}
return m;
}
void gianuocps(int &tu,int &mau)
{
int uc=ucln(tu,mau);
tu=tu/uc;
mau=mau/uc;
}
Bạn đang đọc truyện trên: Truyen247.Pro