| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
刚学了if语句和分支结构,结果第一题就一直卡住了 
题目是 :键盘输入一个英文字母,如果是大写字母,输出ASCII码,如果是小写字母输出对应的大写字母。 
我的答案是:#include <stdio.h> 
int main() 
{ 
    char x; 
    scanf("%c",&x); 
    if(x>='a') 
                x=x-32; 
                printf("%c",x); 
    else 
                printf("%d",x); 
} 
但是这个运行不了,运行出一堆乱码 
a.c: In function ‘main’: 
a.c:6:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 
     if(x>='a') 
     ^~ 
a.c:8:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’ 
   printf("%c",x); 
   ^~~~~~ 
a.c:9:5: error: ‘else’ without a previous ‘if’ 
     else 
     ^~~~ 
a.c:5:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] 
     scanf("%c",&x); 
     ^~~~~~~~~~~~~~ 
请教一下我的错误出在了哪里,正确的这个程序应该怎么写,因为是刚学C语言还请写的简单一点 
c 的代码块加 {} 
int main() 
{ 
    char x; 
    scanf("%c",&x); 
    if(x>='a') 
        { 
                x=x-32; 
                printf("%c",x); 
        } 
    else 
        { 
                printf("%d",x); 
        } 
} 
 
 
 |   
 
 
 
 |