
Câu 1.16: Viết hàm tìm ước chung lớn nhất của 2 số nguyên dương. Viết chương trình nhập vào từ bàn phím 2 số nguyên dương a và b, áp dụng hàm trên tìm và in ra màn hình ước chung lớn nhất của chúng
Monday, August 11, 2014
//
cbai16.cpp : Defines the entry point for the console application.
//
code Dung NV
#include
"stdafx.h"
#include
<stdio.h>
#include
<conio.h>
#include
<math.h>
int
ucln(int x, int
y)
{
x = abs(x);
y = abs(y);
while
(x!=y)
if (x>y) x=x-y; else
y=y-x;
return
x;
}
int
_tmain(int argc, _TCHAR* argv[])
{
int
a,b,c;
printf("Nhap
a: a = "); scanf("%d",&a);
printf("Nhap
b: b = "); scanf("%d",&b);
c = ucln(a,b);
printf("Uoc
chung lon nhat cua 2 so %d va %d la: %d",a,b,c);
getch();
return
0;
}

All comments [ 0 ]
Your comments