Q.) Implemnet atoi function (amazon interview question)
source code:
source code:
#includeint atoi(char s[]) { int i,n; n=0; for(i=0;s[i]>='0'&&s[i]<='9';++i) n=10*n+(s[i]-'0'); return n; } int main() { char s[100]; scanf("%s",s); int num=atoi(s); printf("%d",num); return 0; }
No comments:
Post a Comment