> 本文参考 [嗨客网](https://haicoder.net) Golang [实战](https://haicoder.net/case/index.html) # **Golang编程百例及详细答案** # **前言** 本篇文章是关于 Golang 编程百例的题目以及详细的解题思路,每道题都附有答案链接,答案解题的每个步骤到运行结果都十分详细,十分适合小白拿来练习,也十分适合准备面试的各位复习下 Golang 基础,这篇文章我会不断更新,题目都是对应 Golang 中的各个知识点,大家在学习了 [Golang](https://haicoder.net/golang/golang-tutorial.html) 相关教程之后,做几道相关的练习题,复习一下该知识点,在学习过程中,觉得十分抽象、晦涩难懂的知识点,配合一道案例题,或许会有意想不到的效果哦!   # **正文:Golang编程百例** ## **初级篇** ### **题目一** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,将四个数进行排列组合。 题目:有 1、2、3、4 这四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-1.html](https://haicoder.net/case/golang-hundred-cases/golang-1-1.html) ### **题目二** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,企业发放的奖金根据利润提成的计算。 题目: ​ 企业发放的奖金根据利润提成。利润(I)低于或等于 10 万元时,奖金可提成 10%;利润高于 10 万元,低于 20 万元,低于 10 万元的部分按 10% 提成,高于 10 万元的部分,可提成 7.5%。 ​ 20 万到 40 万之间时,高于 20 万元的部分,可提成 5%;40 万到 60 万之间时高于 40 万元的部分,可提成 3%;60 万到 100 万之间时,高于 60 万元的部分,可提成 1.5%,高于 100 万元时,超过 100 万元的部分按 1% 提成。 ​ 从键盘输入当月利润 I,求应发放奖金总数? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-2.html](https://haicoder.net/case/golang-hundred-cases/golang-1-2.html) ### **题目三** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,计算完全平方数。 题目:一个整数,它加上 100 后是一个完全平方数,再加上 168 又是一个完全平方数,请问该数是多少? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-3.html](https://haicoder.net/case/golang-hundred-cases/golang-1-3.html) ### **题目四** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,随便输入日期,判断时一年的第几天。 题目:输入某年某月某日,判断这一天是这一年的第几天? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-4.html](https://haicoder.net/case/golang-hundred-cases/golang-1-4.html) ### **题目五** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,数字从小到大排序。 题目:输入三个 **[整数](https://haicoder.net/golang/golang-int.html)** x,y,z,请把这三个数由小到大输出。 答案:https://haicoder.net/case/golang-hundred-cases/golang-1-5.html ### **题目六** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,打印字母 C。 题目:用 * 号输出字母 C 的图案。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-6.html]( ### **题目七** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,输出特殊图案。 题目:输出特殊图案。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-7.html](https://haicoder.net/case/golang-hundred-cases/golang-1-7.html) ### **题目八** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,打印乘法口诀。 题目:输出 9*9 乘法口诀表。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-8.html](https://haicoder.net/case/golang-hundred-cases/golang-1-8.html) ### **题目九** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,输出国际象棋棋盘。 题目:输出国际象棋棋盘。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-9.html](https://haicoder.net/case/golang-hundred-cases/golang-1-9.html) ### **题目十** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,打印楼梯。 题目:打印楼梯,同时在楼梯上方打印笑脸。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-10.html](https://haicoder.net/case/golang-hundred-cases/golang-1-10.html) ### **题目十一** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,求解兔子总数问题。 题目:古典问题:有一对兔子,从出生后第 3 个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-11.html](https://haicoder.net/case/golang-hundred-cases/golang-1-11.html) ### **题目十二** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,求素数个数。 题目:判断 101-200 之间有多少个素数,并输出所有素数。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-12.html](https://haicoder.net/case/golang-hundred-cases/golang-1-12.html) ### **题目十三** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,打印出所有的水仙花数。 题目:打印出所有的 “水仙花数”,所谓 “水仙花数” 是指一个三位数,其各位数字立方和等于该数本身。例如:153 是一个 “水仙花数”,因为 153=1 的三次方+5 的三次方+3 的三次方。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-13.html](https://haicoder.net/case/golang-hundred-cases/golang-1-13.html) ### **题目十四** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,分解质因数。 题目:将一个正整数分解质因数。例如:输入 90,打印出 90 = 2 * 3 * 3 * 5。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-14.html](https://haicoder.net/case/golang-hundred-cases/golang-1-14.html) ### **题目十五** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,根据不同的分数输出不同的等级。 题目:利用条件运算符的嵌套来完成此题:学习成绩 >= 90 分的同学用 A 表示,60-89 分之间的用 B 表示,60 分以下的用 C 表示。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-15.html](https://haicoder.net/case/golang-hundred-cases/golang-1-15.html) ### **题目十六** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,求两个数的最大公约数和最小公倍数。 题目:输入两个正整数 m 和 n,求其最大公约数和最小公倍数。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-16.html](https://haicoder.net/case/golang-hundred-cases/golang-1-16.html) ### **题目十七** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,统计一个 **[字符串](https://haicoder.net/golang/golang-string.html)** 中各个字符的个数。 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-17.html](https://haicoder.net/case/golang-hundred-cases/golang-1-17.html) ### **题目十八** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,累计特殊数。 题目:求 s = a + aa + aaa + aaaa + aa…a 的值,其中 a 是一个数字。例如 2+22+222+2222+22222(此时共有 5 个数相加),几个数相加由键盘控制。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-18.html](https://haicoder.net/case/golang-hundred-cases/golang-1-18.html) ### **题目十九** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,找出所有完数。 题目:一个数如果恰好等于它的因子之和,这个数就称为 “完数”。例如 6=1+2+3,编程找出 1000 以内的所有完数。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-19.html](https://haicoder.net/case/golang-hundred-cases/golang-1-19.html) ### **题目二十** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,计算自由落体总共的高度。 题目:一球从100 米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第 10 次落地时,共经过多少米?第 10 次反弹多高? 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-20.html](https://haicoder.net/case/golang-hundred-cases/golang-1-20.html) ### **题目二十一** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,解决猴子吃桃问题。 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个。第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第 10 天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-21.html](https://haicoder.net/case/golang-hundred-cases/golang-1-21.html) ### **题目二十二** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,找出兵乓球对手。 题目:两个乒乓球队进行比赛,各出三人。甲队为 a、b、c 三人,乙队为x、y、z 三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a 说他不和 x 比,c 说他不和 x、z 比,请编程序找出三队赛手的名单。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-22.html](https://haicoder.net/case/golang-hundred-cases/golang-1-22.html) ### **题目二十三** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,打印菱形。 题目:打印出菱形图案。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-23.html](https://haicoder.net/case/golang-hundred-cases/golang-1-23.html) ### **题目二十四** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,计算分数序列的和。 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13…求出这个数列的前 20 项之和。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-24.html](https://haicoder.net/case/golang-hundred-cases/golang-1-24.html) ### **题目二十五** 描述:用 **[Golang](https://haicoder.net/golang/golang-tutorial.html)** 实现,求阶乘和。 题目:求 1+2!+3!+…+20! 的和。 答案:[https://haicoder.net/case/golang-hundred-cases/golang-1-25.html](https://haicoder.net/case/golang-hundred-cases/golang-1-25.html)   # **后续** 因为文章数量过多,整理不易,所以如果更新过慢,请大家谅解,文章我会尽自己最大速度更新,大家可以先关注我,或者收藏下这篇文章,我会持续更新的,以上案例是提供给有一定 Golang 基础的同学看的,如果感觉做题有些压力,可以先在各类教程网先学习 Golang 语言,本人这里当然首推上方习题及答案来源的 **[嗨客网](https://haicoder.net/)**。 ***2020.08.28更,未完待续。。。。。***