Paste
Pasted as C++ by registered user xujiayu ( 4 years ago )
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
// HAY NHAP VAO 1 SO NGUYEN DUONG N (N > 0)
int n;
do
{
printf("\nhay nhap vao so n : ");
scanf("%d",&n);
if(n <= 0)
{
printf("\nso ban nhap khong hop le xin hay nhap lai cam on!");
}
} while (n <= 0);
int temp = n;// luu bien phu , vi minh can hien thi bien chinh n , nen dat 1 gia tri = n de mimh thuc hien nhung thuat toan
int sodaonguoc = 0;
int dem = log10((double)temp); // neu nhap 4321 thi lay ra duoc la 3 chu so
while (temp != 0)
{
int chuso = temp % 10;
temp /= 10;
sodaonguoc += chuso * pow(10.0,dem--); // sodaonguoc + chu so * ^ma so log10 log ra vi vn 4321 la 4*10^3+ 3*10^2+2*10^1+1*10^0
}
//printf("\nso dao nguoc cua %d la %d",n,sodaonguoc);
if(n == sodaonguoc)
{
printf("\nla so doi xung ");
}
else
{
printf("\nkhong phai la so doi xung");
}
getch();
return 0;
}
Revise this Paste