用C語言 ?用指針找出字符串中的數(shù)字并相加,輸出asII值。例,a1b2c3 怎么做
1 回答

denmushi
TA貢獻9條經(jīng)驗 獲得超0個贊
#include?<stdio.h> int?main(){ ????char?str[]?=?"a1b2c3"; ????char*?p?=?str; ????int?s?=?0; ????printf("數(shù)字有:"); ????while(p){ ????????if(*p>='0'&&*p<='9'){ ????????????s?+=?(*p?-?'0'); ????????????printf("%d",*p?-?'0'); ????????} ????????p++; ????} ????printf("\n求和為:%d\nASCII碼為:%d\n",s,s+'0'); ???? ????return?0; }
- 1 回答
- 0 關注
- 1249 瀏覽
添加回答
舉報
0/150
提交
取消