第十一周编程总结

Posted chenguohhw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十一周编程总结相关的知识,希望对你有一定的参考价值。

第十一周编程总结

题目1:11-1 打印九九口诀表 (15 分)

下面是一个完整的下三角九九口诀表:

1*1=1  

1*2=2   2*2=4  

1*3=3   2*3=6   3*3=9  

1*4=4   2*4=8   3*4=12  4*4=16 

1*5=5   2*5=10  3*5=15  4*5=20  5*5=25 

1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36 

1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49 

1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64 

1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81 

本题要求对任意给定的一位正整数N,输出从1*1到N*N的部分口诀表。

1).实验代码

#include<stdio.h>

int main()

{

  int n;

  scanf("%d",&n);

  for(int i = 1;i <=n ;i++){

    for(int j = 1;j <= i;j++){

      if(i * j >= 10){

        printf("%d*%d=%d  ", j, i, j * i); //2格

      }

      else{

        printf("%d*%d=%d   ", j, i, j * i);//3格

      }

    }

    printf(" ");

  }

  return 0;

}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

2).设计思路

第一步 考虑到使用嵌套语句循环,输入一个整数

第二步 定义i从1开始循环到n停止

第三步 定义一个j从1开始循环到i停止

第四步 格式化输出,当i和j的成绩大于10的时候要空2格,否则空3格

3)本题调试中遇到的问题及解决方案

在输出乘法表的时候出现空格问题,不知道如何去打印

4).运行结果截图

 

 

        

 

题目2:11-2 换硬币 (20 分)

将一笔零钱换成5分、2分和1分的硬币,要求每种硬币至少有一枚,有几种不同的换法?

1).实验代码

#include<stdio.h>

int main()

{

  int x,count=0;

  scanf("%d",&x);

  for ( int k = x / 5; k > 0; k-- )

  for ( int i = x / 2; i > 0; i-- )

  for ( int j = x; j > 0; j-- )

  if(k*5+i*2+j==x){

    printf("fen5:%d, fen2:%d, fen1:%d, total:%d ", k, i, j, k + j + i);

    count++;

  }

  printf("count = %d",count);

  return 0;

}

2).设计思路

第一步 输入零钱x

第二步 使用嵌套循环定义一个k从x/5开始循环,定义一个i从i/2开始循环,定义一个j从x开始循环,不断累减

第三步 当满足k*5+i*2+j==x条件时进行输出,此时就是对应的硬币数

4).运行结果截图

 

题目3:11-3 找完数 (20 分)

所谓完数就是该数恰好等于除自身外的因子之和。例如:6=1+2+3,其中1、2、3为6的因子。本题要求编写程序,找出任意两正整数mn之间的所有完数。

1).实验代码

#include<stdio.h>

int main(){

       int n,m,i,j,sum,num=0;

       scanf("%d %d",&m,&n);

       for(i=m;i<=n;i++){

              if(i==1) continue;

              sum=1;

              for(j=2;j<i;j++)

                     if(i%j==0) sum+=j;

              if(sum==i){       

                     printf("%d = 1",i); 

                     for(j=2;j<i;j++)

                            if(i%j==0)

                                   printf(" + %d",j);

                     printf(" ");

                     num++;

              }

       }

       if(num==0) printf("None ");

       return 0;

}

2).设计思路

第一步 输入2个数m、n      

第二步 i从m开始循环到n结束,定义的j从2开始循环到i停止不断累加

第三步 用sum来累加能整出的数

第四步 如果sum==i说明完数只有1

3)本题调试中遇到的问题及解决方案

嵌套循环次数使用的次数过多,自己都有点晕

4).运行结果截图

 

以上是关于第十一周编程总结的主要内容,如果未能解决你的问题,请参考以下文章

第十一周编程总结

第十一周课程总结

第十一周课程总结

第十一周java课程学习总结

《JAVA程序设计》第十一周学习总结

20175227张雪莹 2018-2019-2 《Java程序设计》第十一周学习总结