| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 423 人关注过本帖
标题:感激不尽!希望大家检查这个程序有什么毛病,谢谢!
取消只看楼主 加入收藏
江东周公瑾
Rank: 1
来 自:火星
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-18
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:0 
感激不尽!希望大家检查这个程序有什么毛病,谢谢!
#include<stdio.h>
int main(){
    int c1,c2;                                                          /*c1 c2是字符串数量*/
    scanf("%d%d",&c1,&c2);                                              /*得到c1c2数值*/
    char ch1[20],ch2[20];                                               /*两个字符串*/
    int a,b,k=0;                                                            /*循环变量 K记录相等数量*/
    for(a=0;a<c1;a++)
    scanf("%c",ch1[a]);
    for(b=0;b<c2;b++)
    scanf("%c",ch2[b]);                                                 /*得到字符串*/
                        if(c1<c2){                                                         /*比较c1c2大小*/
                                   for(a=0;a<c1;a++)
                                   printf("%c",ch1[a]);
                                   printf("\n");
                                   for(b=0;b<c2;b++)
                                   printf("%c",ch2[b]);
    }
    else               if(c1>c2){
                                   for(b=0;b<c2;b++)
                                   printf("%c",ch2[b]);
                                   printf("\n");
                                   for(a=0;a<c1;a++)
                                   printf("%c",ch1[a]);
    }
    else     for(a=0;a<c1;a++){
             if(ch1[a]>ch2[a]){
                               for(b=0;b<c1;b++)
                                                printf("%c",ch2[b]);
                               printf("\n");
                               for(b=0;b<c1;b++)
                               printf("%c",ch1[b]);
                               break;
                               }
             if(ch2[a]>ch1[a]){
                               for(b=0;b<c1;b++)
                                                printf("%c",ch1[b]);
                               printf("\n");
                               for(b=0;b<c1;b++)
                               printf("%c",ch2[b]);
                               break;
                               }
              else ++k;
              if(k==c1){
                        for(b=0;b<c1;b++)
                                                printf("%c",ch2[b]);
                               printf("\n");
                               for(b=0;b<c1;b++)
                               printf("%c",ch1[b]);
                               break;
                               }

}      
return 0;
}      






此程序目的是得到两个字符串,并按照ASCII的顺序输出。编译通过,但在运行时提示错误,这是为什么呢?
搜索更多相关主题的帖子: 毛病 感激不尽 检查 
2010-06-18 09:41
快速回复:感激不尽!希望大家检查这个程序有什么毛病,谢谢!
数据加载中...
 
   



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

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