TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/
- /*
- 9. 在主函数内任意输入一个5×6矩阵,编写一函数求出每一行的和放到一个一维数组中,
- 输出此矩阵及其每一行的和。
-
- */
- /************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
-
- void main()
- {
- int arr[5][6]={0};
- int sum[5]={0};
- for (int i=0;i<5;i++) // 初始化矩阵
- {
- for(int j=0;j<6;j++)
- {
- arr[j]=rand()%100;
- }
- }
-
- for (int i=0;i<5;i++) // 累加
- {
- int s=0;
- for(int j=0;j<6;j++) // 某一行的累加
- {
- s+=arr[j];
- }
- sum=s; // 累加结果保存在sum
- }
- for (int i=0;i<5;i++) // 打印结果
- {
- for(int j=0;j<6;j++)
- {
- printf("%5d",arr[j]);
- }
- printf("这行的和为:%d",sum);
- printf("\n");
- }
- system("pause");
- }</pre><br><br></pre></pre>
|
|