Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // max 10 digists for a 32 bit number plus enter
- char NUMBER[13];
- // return length of a newline terminated string
- int strLen( char *a0 ) {
- int t1 = 0;
- while ( *a0 != 10 ) {
- t1++;
- a0++;
- }
- return t1;
- }
- int main(void) {
- int s1, s2, s3, t1;
- while ( fgets(NUMBER, 12, stdin) != NULL ) {
- s1 = strLen(NUMBER);
- s2 = 1; // column
- s3 = 0; // result
- t1 = 0; // temp
- s1--; // adjust to be an index
- while ( s1 != -1 ) {
- // check that the char is a digit
- t1 = *(NUMBER+s1);
- if ( t1 < '0' || t1 > '9' )
- goto error;
- t1 = t1 - '0';
- s3 += t1 * s2;
- s2 *= 10;
- s1--;
- }
- printf("%d\n", s3);
- if ( s3 >= 100 )
- break;
- }
- return 0;
- error:
- printf("error\n");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement