fuliver123

Đếm ước chung 2 số - Thực hành tin đại cương

Nov 30th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int k=0;
  4. int ucln(int a, int b)
  5. {
  6.     return a==0?b:ucln(b%a,a);
  7. }
  8.  
  9. int uoc(int a)
  10. {
  11.     int i,s=0;
  12.     for (i=1;i*i<a;i++)
  13.         if (a%i==0)
  14.         {
  15.             s=s+i+a/i;
  16.             k+=2;
  17.         }
  18.     if (i*i!=a) return s;
  19.     s=s+i;
  20.     k++;
  21.     return s;
  22. }
  23.  
  24. int main()
  25. {
  26.     int a,b;
  27.     printf("Nhap vao so thu 1: "); scanf("%d",&a);
  28.     printf("Nhap vao so thu 2: "); scanf("%d",&b);
  29.     printf("Tong cac uoc chung cua %d va %d la: %d\n",a,b,uoc(ucln(a,b)));
  30.     printf("Co tat ca %d uoc chung cua %d va %d.",k,a,b);
  31.     getch();
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment