C語言問題~求高手~?
26個英文字對應數字如:a = 1 , b=2....等...
如我隨便打出三個英文字~再將佢地對應的數字相加如: a b c... 1+2+3 = 6,將最後結果6印出 應如何實現呢??THX
回答 (3)
#include <stdio.h>
int main(void) {
for(;;){
int s,i;
for(s=0; scanf("%c",&i)&&(i!='\n'); s+= i-'a'+1);
printf("%d\n",s);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char c_in;
int sum=0;
while((scanf("%c",&c_in))&&(c_in!='\n'))
{
sum+=c_in-'a'+1;
}
printf("%d\n",sum);
system("pause");
return 0;
}
收錄日期: 2021-05-04 02:14:42
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20161227123315AAKpcuO
檢視 Wayback Machine 備份