这道题我使用一个长度为256的字符数组存储输入,然后令sum=0,从a[0]开始遍历,如果当前的a[i]是大写字母,则计算这个大写字母的ASCII码-64后乘i+1的值,将该值加到sum中,最后输出sum。
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int js(char a[]){ 5 int i=0,sum=0; 6 for(i=0;a[i]!='