Advertisement
Guest User

6digits

a guest
Feb 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. unsigned long charToInt(char c) {
  4.     switch (c) {
  5.         case '0': return 0;
  6.         case '1': return 1;
  7.         case '2': return 2;
  8.         case '3': return 3;
  9.         case '4': return 4;
  10.         case '5': return 5;
  11.         case '6': return 6;
  12.         case '7': return 7;
  13.         case '8': return 8;
  14.         case '9': return 9;
  15.     }
  16. }
  17.  
  18. int main(void) {
  19.     unsigned long total = 0;
  20.    
  21.     for (int i = 0; i < 6; ++i) {
  22.         total = total * 10 + charToInt(getchar());
  23.     }
  24.    
  25.     printf("You entered number: %d\n", total);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement