Advertisement
nguyenhappy92

Tính tổng của các chữ số của một số tự nhiên n

Oct 16th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. // Tinh tong cac chu so nguyen duong n
  2. // Khai bao ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8. int n;
  9. scanf("%d",&n);
  10. long s=0;
  11. int a;
  12. while(n!=0)
  13. {
  14. a=n%10;
  15. s=s+a;
  16. n=n/10;
  17. }
  18. printf("%ld\n",s);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement