Paste
Pasted as C++ by registered user xujiayu ( 5 years ago )
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
//nhap VAO SO XE BAO GOM 5 CHU SO TINH SO NUT
int soxe;
printf("\nhay nhap vao so xe : ");
scanf("%d",&soxe);
int sochuso;
sochuso = log10 ((float)soxe) + 1;
//printf("\nso %d co %d chu so !",soxe,sochuso);
/*
12345=>1 + 2 + 3 + 4 + 5 = 15 => 5 nut
12345 % 10 = 5
12345 / 10 = 1234
*/
int sonut = 0;
sonut += soxe % 10;// lan 1
soxe /= 10; // bo so cuoi
sonut += soxe % 10;// lan 2
soxe /= 10; // bo so cuoi
sonut += soxe % 10;// lan 3
soxe /= 10; // bo so cuoi
sonut += soxe % 10;// lan 4
soxe /= 10; // bo so cuoi
sonut += soxe % 10;// lan 5
soxe /= 10; // bo so cuoi
sonut += soxe;
sonut %= 10; // lay hang don vi
sochuso == 5 ? printf("\nso nut = %d",sonut) : printf("xin hay nhap dung 5 chu so cam on");
getch();
return 0;
}
Revise this Paste
Parent: 116849