标题:哪里出错?真心求教!
只看楼主
tanlunqiang
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2012-11-1
结帖率:0
 问题点数:0 回复次数:8 
哪里出错?真心求教!
问题:输入任意长度字符,要求将其对应的大写字母输出
#include<stdio.h>
int main()
{
    int c;
    printf("请输入任意数c:");
    scanf("%d",&c);
    switch(c);
    {
        case'c%26==0':printf("c=A");break;
        case'c%26==1':printf("c=B");break;
        case'c%26==2':printf("c=C");break;
        case'c%26==3':printf("c=D");break;
        case'c%26==4':printf("c=E");break;
        case'c%26==5':printf("c=F");break;
        case'c%26==6':printf("c=G");break;
        case'c%26==7':printf("c=H");break;
        case'c%26==8':printf("c=I");break;
        case'c%26==9':printf("c=J");break;
        case'c%26==10':printf("c=K");break;
        case'c%26==11':printf("c=L");break;
        case'c%26==12':printf("c=M");break;
        case'c%26==13':printf("c=N");break;
        case'c%26==14':printf("c=O");break;
        case'c%26==15':printf("c=P");break;
        case'c%26==16':printf("c=Q");break;
        case'c%26==17':printf("c=R");break;
        case'c%26==18':printf("c=S");break;
        case'c%26==19':printf("c=T");break;
        case'c%26==20':printf("c=U");break;
        case'c%26==21':printf("c=V");break;
        case'c%26==22':printf("c=W");break;
        case'c%26==23':printf("c=X");break;
        case'c%26==24':printf("c=Y");break;
        case'c%26==25':printf("c=Z");break;
    }
    return 0;
}

与我不同的还可以用什么方法?
搜索更多相关主题的帖子: 真心 字母 include 
2012-11-01 23:18
caobo3
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-30
得分:0 

#include<stdio.h>
int main()
{
    int c;
    printf("请输入任意数c:");
    scanf("%d",&c);
    switch (c)
    {
    case 0:
         if (c%26==0)
        printf("c=A\n");
        break;
    case 1:
        if(c%26==1)
        printf("c=B\n");
        break;
    case 2:
        if (c%26==2)
        printf("c=C\n");
        break;
    case 3:
        if(c%26==3)
        printf("c=D\n");
        break;
    case 4:
        if(c%26==4)
        printf("c=E\n");
        break;
    case 5:
        if(c%26==5)
        printf("c=F\n");
        break;
    case 6:
        if(c%26==6)
        printf("c=G\n");
        break;
    case 7:
        if(c%26==7)
        printf("c=H\n");
        break;
    case 8:
        if(c%26==8)
        printf("c=I\n");
        break;
    case 9:
        if(c%26==9)
        printf("c=J\n");
        break;
    case 10:
        if(c%26==10)
        printf("c=K\n");
        break;
    case 11:
        if(c%26==11)
        printf("c=L\n");
        break;
    case 12:
        if(c%26==12)
        printf("c=M\n");
        break;
    case 13:
        if(c%26==13)
        printf("c=N\n");
        break;
    case 14:
        if(c%26==14)
        printf("c=O\n");
        break;
    case 15:
        if(c%26==15)
        printf("c=P\n");
        break;
    case 16:
        if(c%26==16)
        printf("c=Q\n");
        break;
    case 17:
        if(c%26==17)
        printf("c=R\n");
        break;
    case 18:
        if(c%26==18)
        printf("c=S\n");
        break;
    case 19:
        if(c%26==19)
        printf("c=T\n");
        break;
    case 20:
        if(c%26==20)
        printf("c=U\n");
        break;
    case 21:
        if(c%26==21)
        printf("c=V\n");
        break;
    case 22:
        if(c%26==22)
        printf("c=W\n");
        break;
    case 23:
        if(c%26==23)
        printf("c=X\n");
        break;
    case 24:
        if(c%26==24)
        printf("c=Y\n");
        break;
    case 25:
        if(c%26==25)
        printf("c=Z\n");
        break;
    default:
        printf("请输入0-26之间的数!\n");
        break;
    }
}
2012-11-02 00:04
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:0 
虽然你没放分   送你一段代码吧  
#include <stdio.h>
#include <ctype.h>
void main()
{
    char s1[20];
    for(int i=0;i<20;i++) s1[i]='\0';
    printf("请输入任意字符串:");
    scanf("%s",&s1);
    for(int j=0;j<20;j++) s1[j]=toupper(s1[j]);
    printf("更改后的字符串输出为:%s",&s1);
}

DO IT YOURSELF !
2012-11-02 09:04
liman123
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:79
专家分:178
注 册:2012-10-6
得分:0 
这样做实在太繁琐了,switch语句最好少用
2012-11-02 09:38
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
得分:0 
写那么多干嘛,
#include<stdio.h>
main()
{
    int c,x;
    printf("enter a number.\n");
    scanf("%d",&c);
    x=c%26+65;
    printf("c=%c",x);
    return 0;
}
不就行了吗,还有啊,switch(c)中c所能带入的只能是一个值,而不能是一个判断式,比如0,1,2等数字或a,b,c之类的字母,所以用switch之前要先判断好,不要把判断式带入switch中,所以switch其实很麻烦的,尽量少用,else if()用好了也能达到一样的效果,还有最后一个case不用break的,或者用default

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-02 10:30
tanlunqiang
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2012-11-1
得分:0 
回复 5楼 yaobao
哦,明白了~~
2012-11-02 15:45
tanlunqiang
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2012-11-1
得分:0 
回复 2楼 caobo3
太长了吧!
2012-11-02 15:48
枫叶飘落
Rank: 2
等 级:论坛游民
帖 子:35
专家分:66
注 册:2012-10-27
得分:0 
用if~else
2012-11-02 23:19
hfhf2006
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:62
专家分:169
注 册:2012-6-29
得分:0 
晕,case后面是常量或常量表达式,你的程序能运行吗?
2012-11-02 23:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-385560-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.320009 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved