Bài 50: Tìm chữ số đảo ngược của số nguyên dương n
//========================================//Cách 1
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int n;
scanf("%d", &n);
int dn = 0;
int t = abs(n);
while (t != 0)
{
int dv = t%10;
dn = dn*10 + dv;
t = t/10;
}
printf("%d", dn);
}
//========================================
//Cách 2
/*
#include <stdio.h>
#include <conio.h>
#include <math.h>
int DaoNguoc(int);
void main()
{
int n;
scanf("%d", &n);
int kq = DaoNguoc(n);
printf("%d", kq);
}
int DaoNguoc(int k)
{
int dn = 0;
int t = abs(k);
while (t != 0)
{
int dv = t%10;
dn = dn*10 + dv;
t = t/10;
}
return dn;
}
*/
No comments:
Post a Comment