问答详情
源自:2-1 有名有姓的C

新手求救大佬

5a07c48b000167ec07440992.jpg
求解!

提问者:慕仰8146024 2017-11-12 11:49

个回答

  • 慕侠8100721
    2017-11-12 16:23:57
    已采纳

    #include <stdio.h>

    int main()

    {

           int x=0,y=0;

            int n;

            char a;

            printf("请输入要参与运算的字母数,必须2-1000个\n");

            scanf("%d",&x);

             for(int m=0;m<x;m++)

                {

                    scanf("%c   ",&a);

                    if(65<=a<=90)

                     n=(int) a-64;

                    else if(97<=a<=122)

                        n=(int) a-96;

                    y=y+n;

                }

              printf("\n%d",y);

    return 0;

    }  


  • 慕侠8100721
    2017-11-12 17:02:54

    #include <stdio.h>

    int main()

    {

    int x=0,y=0;

    int n;

    char a;

    printf("请输入要参与运算的字母数,必须2-1000个\n");

    scanf("%d",&x);

    for(int m=0;m<x;m++)

    {

    getchar();

    scanf("%c",&a); 

    n= (int) a;

    if(65<=n && n<=90)

    n=n-64;

    else if(97<=n && n<=122)

    n=n-96;

    y=y+n;

    }

      printf("\n%d",y);

    return 0;