Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char arr[8];
- scanf("%s",arr); //take input
- int sign=1, ind=0, num=0;
- //check for negative number
- if(arr[0]=='-')
- {
- sign = -1;
- ind = 1;
- }
- //convert char array into integer
- while(arr[ind]!='\0')
- {
- if(arr[ind]>='0' && arr[ind]<='9')
- num = num*10+arr[ind]-'0';
- else
- break;
- ind++;
- }
- //if input was given negative it'll turn into negative number
- num*=sign;
- printf("%d\n",num); //print output
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement