Implementation of function “atoi()” and sum of the converts integers digites.

#include<stdio.h>
#include<string.h>
main()
{ int i,n,l,j=0,sum=0;
char ch,str[10],*p;
puts("Enter the string which you want to convert in interger::");
gets(str);
l=strlen(str);
p=str;
int a[l];

while((*p)!='' && j<l)
{ //printf("\nc=%c\n",*p);
i=*p-48;
//printf("\nd=%d\n",i);
a[j]=i;
j++;
p++;
}

printf("\nThe integer is:: ");
for(i=0; i<l;i++)
printf("%d",a[i]);
printf("\nSum of the digites of the integer::\n");
for(i=0;i<l;i++)
sum+=a[i];
printf("Sum= %d\n",sum);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s