1、
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX 100
int main()
{
int i;
int sum = 0;
int final = 0;
int len = 0;
char src[MAX];
printf("please input the string:\n");
gets(src);
len = strlen(src);
// for(i = 0; i < len; i++)
// {
// sum = src[i] - '0';
// final += sum *pow(10,len - i-1);
// }
for( i = 0; i < len; i++)
{
final = final * 10 + (src[i] - '0');
}
printf("final is %d\n",final);
return 0;
}
2、
#include <stdio.h>
#define MAX 100
int main()
{
int i;
int sum = 0;
int k = 0;
int len = 0;
char a[MAX];
printf("please input astring:\n");
gets(a);
len =strlen(a);
for(i = 0 ; a[i] !='\0'; i++)
{
while(a[i] >= '0'&&a[i] <= '9')
{
k = k*10 + (a[i] - '0');
i++;
}
sum += k;
k = 0;
}
printf("the sum is %d\n",sum);
return 0;
}
3、
#include <stdio.h>
#define MAX 100
int main()
{
int n;
int len = 0;
int i = 0;
int temp = 0;
char string[MAX];
printf("please input a number:\n");
scanf("%d",&n);
while(n != 0)
{
string[i] = n % 10 + '0';
n = n / 10;
i++;
}
string[i] = '\0';
len = strlen(string);
/* for(i = 0; i < len / 2; i++)
{
temp = string[i];
string[i] = string[len - i - 1];
string[len - i - 1] = temp;
}*/
for(i = 0; i < len; i++)
{
string[i]=string[len - i -1];
}
printf("the string is %s\n",string);
return 0;
}