kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Hai, 16 tháng 3, 2015


Đề bài: nhận vào 1 số nguyên n (n>=0) . Hãy:
- đếm số chữ số của số nguyên n đó
- tính các các chữ số trong số nguyên n
- đảo ngược số nguyên dương n

các yêu cầu được viết bằng kỹ thuật lập trình chương trình con

Bài giải:


#include <stdio.h>
#include <math.h> //su dung ham pow - luy thua
int soChuSo(int n){
int
dem=0;
while
(n>0){
dem++;
n=n/10;
}

return
dem;
}

int
tinhTong(int n){
int
tong=0;
while
(n>0){
tong=tong+(n%10);
n=n/10;
}

return
tong;
}



int
daoNguoc(int n){
int
mu = soChuSo(n)-1;
int
kq=0;
while
(n>0){
int
m = (n%10)*pow(10,mu);
kq=kq+m;
n =n/10;
mu--;
}

return
kq;
}

int
main(){
int
n;
printf("Nhap vao so nguyen n : ");
scanf("%d",&n);
int
scs = soChuSo(n);
printf("So chu so (%d) = %d",n,scs);
int
tcs = tinhTong(n);
printf("\nTong cac so trong so (%d) = %d",n,tcs);
int
sdn = daoNguoc(n);
printf("\nDao nguoc(%d) = %d",n,sdn);

return
0;
}

Xem Video:
16 Mar 2015

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Bài đăng phổ biến