Thursday, December 4, 2014

Bài 29

Bài 29: Tìm ước số lẻ lớn nhất của số nguyên dương n

- Lưu ý #include <math.h>

//========================================
//Cách 1

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
    int n;
    scanf("%d", &n);
    int t = abs(n);
    while (t%2 == 0)
    {
        t = t/2;
    }
    printf("%d", t);
}

//========================================
//Cách 2
/*
#include <stdio.h>
#include <conio.h>
#include <math.h>

int UocSo(int);
void main()
{
    int n;
    scanf("%d", &n);
    int kq = UocSo(n);
    printf("%d", kq);
}

int UocSo(int k)
{
    int t = abs(k);
    while (t%2 == 0)
    {
        t = t/2;
    }
    return t;
}
*/

No comments:

Post a Comment