IvoSilva

[PROG1] Ficha 4 | Exercício 1

Nov 6th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int n , num , soma ;
  5.     soma = 0 ;
  6.     printf ("Insira um número? ") ;
  7.     scanf ("%d" , &num) ;
  8.     while (num > 0)
  9.     {
  10.         n = num % 10 ;
  11.         num = num / 10 ;
  12.         soma += n ;
  13.     }
  14.     printf ("A soma dos dí­gitos é %d.\n" , soma) ;
  15.     return 0 ;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment