Bài Giải
/*
Name: UCLN BCNN cua 2 so
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include<stdio.h>
//Tim bang phuong phap DE QUY
int UCLNPS(int a, int b)
{
if (a==b)
return a;
else
{
if (a>b)
return UCLNPS(a-b,b);
else
return UCLNPS(a,b-a);
}
}
//Tim bang phuong phap vong lap thong thuong
int UCLN(int a, int b)
{
int k;
if (a==b)
k=a;
else
{
if (a<b)
k=a;
else
k=b;
while((a%k!=0)||(b%k!=0))
{
k--;
}
}
return k;
}
//Tim BCNN bang thuat
int BCNNPS(int a, int b)
{
return a*b/UCLNPS(a,b);
}
// Tim BCNN bang vong lap
int BCNN(int a, int b)
{
int k;
if (a>b)
k=a;
else
k=b;
while (k%a!=0||k%b!=0)
k++;
return k;
}
main()
{
//Trang tri chuong trinh
int i;
printf("\t");
for (i=1;i<30;i++) printf("* ");
printf("\n\t\t CHUONG TRINH TIM UCLN VA BCNN\n\n");
//Het doan chuong trinh trang tri
int u,v;
printf("\t- Nhap vao so A= "); scanf("%d",&u);
printf("\t- Nhap vao so B= "); scanf("%d",&v);
printf("\n\t\t----Phuong Phap Vong Lap Thong Thuong----\n");
printf("\t=> UCLN cua %d va %d la: %d\n",u,v,UCLN(u,v));
printf("\t=> BCNN cua %d va %d la: %d",u,v,BCNN(u,v));
printf("\n\n\t\t----Phuong Phap DE QUY VA THUAT----\n");
printf("\t=> UCLN cua %d va %d la: %d\n",u,v,UCLNPS(u,v));
printf("\t=> BCNN cua %d va %d la: %d",u,v,BCNNPS(u,v));
printf("\n\n\n\n\t\t\t\t http://tvlaptrinh.blogspot.com");
getch();
return 0;
}
Name: UCLN BCNN cua 2 so
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include<stdio.h>
//Tim bang phuong phap DE QUY
int UCLNPS(int a, int b)
{
if (a==b)
return a;
else
{
if (a>b)
return UCLNPS(a-b,b);
else
return UCLNPS(a,b-a);
}
}
//Tim bang phuong phap vong lap thong thuong
int UCLN(int a, int b)
{
int k;
if (a==b)
k=a;
else
{
if (a<b)
k=a;
else
k=b;
while((a%k!=0)||(b%k!=0))
{
k--;
}
}
return k;
}
//Tim BCNN bang thuat
int BCNNPS(int a, int b)
{
return a*b/UCLNPS(a,b);
}
// Tim BCNN bang vong lap
int BCNN(int a, int b)
{
int k;
if (a>b)
k=a;
else
k=b;
while (k%a!=0||k%b!=0)
k++;
return k;
}
main()
{
//Trang tri chuong trinh
int i;
printf("\t");
for (i=1;i<30;i++) printf("* ");
printf("\n\t\t CHUONG TRINH TIM UCLN VA BCNN\n\n");
//Het doan chuong trinh trang tri
int u,v;
printf("\t- Nhap vao so A= "); scanf("%d",&u);
printf("\t- Nhap vao so B= "); scanf("%d",&v);
printf("\n\t\t----Phuong Phap Vong Lap Thong Thuong----\n");
printf("\t=> UCLN cua %d va %d la: %d\n",u,v,UCLN(u,v));
printf("\t=> BCNN cua %d va %d la: %d",u,v,BCNN(u,v));
printf("\n\n\t\t----Phuong Phap DE QUY VA THUAT----\n");
printf("\t=> UCLN cua %d va %d la: %d\n",u,v,UCLNPS(u,v));
printf("\t=> BCNN cua %d va %d la: %d",u,v,BCNNPS(u,v));
printf("\n\n\n\n\t\t\t\t http://tvlaptrinh.blogspot.com");
getch();
return 0;
}
Không có nhận xét nào:
Đăng nhận xét