标题:关于数组,有个不懂的问题求大神解答
取消只看楼主
qq7918640
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2017-11-26
结帖率:77.78%
已结贴  问题点数:13 回复次数:4 
关于数组,有个不懂的问题求大神解答
这是原题
程序代码:
#include <stdio.h>
main()
{
&nbsp;&nbsp;&nbsp;&nbsp;int n;
&nbsp;&nbsp;&nbsp;&nbsp;char monthName[][20] = {Illegal month, January, February, March, April, May, June, July, August, September, October, November, December};
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;printf("Input month number:");
&nbsp;&nbsp;&nbsp;&nbsp;scanf("%d", n);
&nbsp;&nbsp;&nbsp;&nbsp;if ((n < 12) || (n > 1))
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("month %d is %c\n", n, monthName[n][n]);
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s\n", monthName[0][0]);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
搜索更多相关主题的帖子: 数组 printf number scanf if 
2018-01-02 10:10
qq7918640
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2017-11-26
得分:0 
这是答案
程序代码:
#include <stdio.h>
main()
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;int n;
&nbsp;&nbsp;&nbsp;&nbsp;char monthName[][20] = {"Illegal month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;printf("Input month number:");
&nbsp;&nbsp;&nbsp;&nbsp;scanf("%d", &n);
&nbsp;&nbsp;&nbsp;&nbsp;if ((n <= 12) && (n >= 1))
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("month %d is %s\n", n, monthName[n]);
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s\n", monthName[0]);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
2018-01-02 10:10
qq7918640
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2017-11-26
得分:0 
貌似程序贴错了,不影响我想问的是为啥题目都是二维数组,而答案给的输出确实一维数组的结构?
2018-01-02 10:11
qq7918640
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2017-11-26
得分:0 
有个新问题,调试发现b的值老是不对,但是又检查不出错误,求解。
程序代码:
#include<stdio.h>
int main()
{
   static int a[3][4]={{1,3,5,7},{2,4,6,8},{15,17,34,12}};
   int b=0,i=0,j=0;
   b=a[0][0];
   for(i=0;i<3;i++)
   {
       for(j=0;i<4;j++)
       {
           if(b<a[i][j])
           b=a[i][j];
       }
   }
   printf("max value is %d\n",b);
   return 0;
}
2018-01-02 10:41
qq7918640
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2017-11-26
得分:0 
额这个我发现了,但是第一个为啥用二维数组解答呀
2018-01-02 11:28



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




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

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