1. 求1到100之内的所有质数,并打印到屏幕上

package main

import "fmt"

// 求1-100 内的质数
func justfy(i int) bool {
if i <= {
return false
} for j := ; j <= i/; j++ {
if i%j == {
return false
}
} return true
} func exp() {
for i := ; i <= ; i++ {
if justfy(i) {
fmt.Printf("%d is 质数\n", i)
}
}
} func main() {
exp()
}

2. 求出 100-999 之间所有的水仙花数

package main

import "fmt"

func issxh(i int) bool {
ge := i %
shi := (i / ) %
bai := i / sum := ge*ge*ge + shi*shi*shi + bai*bai*bai if sum == i {
return true
} else {
return false
} } func exp() {
for i := ; i <= ; i++ {
if issxh(i) {
fmt.Printf("%d 是水仙花数\n", i)
}
}
} func main() {
// fmt.Println(111 / 10)
exp()
}

3.输入一个字符,分别统计出其中英文字目、空格、数字和其它字符的个数

package main

import "fmt"

// 求一个字符串中英文个数  空格个数 数字个数 其他个数
// 字符串用双引号 字符 用单引号
func counttest(str string) (charCount, spaceCount, numCount, otherCount int) {
utf8_str := []rune(str)
for i := ; i < len(utf8_str); i++ {
if (utf8_str[i] >= 'a' && utf8_str[i] <= 'z') || (utf8_str[i] >= 'A' && utf8_str[i] <= 'Z') {
charCount++
continue
} else if utf8_str[i] == ' ' {
spaceCount++
continue
} else if utf8_str[i] >= '' && utf8_str[i] <= '' {
numCount++
continue
} else {
otherCount++
continue
}
}
return
} func main() {
str := "yunnan is beautiful 云南欢迎你 123"
charCount, spaceCount, numCount, otherCount := counttest(str)
fmt.Printf("charCount = %d \n spaceCount=%d \n numCount=%d \n otherCount=%d \n", charCount, spaceCount, numCount, otherCount)
}

go 函数举例练习的更多相关文章

  1. Windows下编程2----- C语言常用函数举例

    几个小函数 1.    //MessageBoxA(0,"网络故障,重新登录","qq error",3); //弹出对话框 2.    //ShellExec ...

  2. SQL SERVER 函数举例

    需求说明 将字符串按照指定的分隔符进行分割,并将结果按照从后往前的顺序倒序排列,拼接后的结果用‘/’符连接.(也可以按照指定符号分割为多个列,修改最后一部分即可) 创建测试表及数据 /* 创建一张测试 ...

  3. Spark--sql--所有函数举例(spark-2.x版本)

    ! expr - Logical not. % expr1 % expr2 - Returns the remainder afterexpr1/expr2. Examples: > SELEC ...

  4. 1.forEach():遍历数组,并为每个元素调用传入的函数; 举例:

    var a = [1,2,3]; var sum = 0; //传一个参数 a.forEach(function(v){ sum += v; }); console.log(sum);//6 //传三 ...

  5. getchar()函数举例

    #include<stdio.h>void main(){ char ch; ch=getchar(); printf("%c",ch);}

  6. Python标准模块--built-ins函数

    1.Python内置函数 2.Python内置函数举例 2.1 数学运算 abs,计算绝对值: >>> abs(-1) 1 >>> abs(3) 3 round,四 ...

  7. Matlab中函数定义方法

    Matlab自定义函数的六种方法 n1.函数文件+调用函数(命令)文件:需单独定义一个自定义函数的M文件: n2.函数文件+子函数:定义一个具有多个自定义函数的M文件: n3.Inline:无需M文件 ...

  8. 字符串哈希函数(String Hash Functions)

    哈希函数举例 http://www.cse.yorku.ca/~oz/hash.html Node.js使用的哈希函数 https://www.npmjs.org/package/string-has ...

  9. Python 常用函数大体分类

    ==================系统库函数================ 字符串函数 举例数学函数 import math val=math.sin(3.14/6) val=math.sin(m ...

随机推荐

  1. Django 2.0 学习(19):Django 分页器

    Django 分页器 要使用Django实现分页功能,必须从Django中导入Paginator模块(painator - 分页器) views.py from django.shortcuts im ...

  2. 【大数据】MapTask工作机制

    1.MapTask工作机制 整个map阶段流程大体如上图所示.简单概述:input File通过getSplits被逻辑切分为多个split文件,通通过RecordReader(默认使用lineRec ...

  3. [BZOJ4446]SCoi2015 小凸玩密室 树形DP(烧脑高能预警)

    4446: [Scoi2015]小凸玩密室 Time Limit: 10 Sec  Memory Limit: 128 MB Description 小凸和小方相约玩密室逃脱,这个密室是一棵有n个节点 ...

  4. winrar 授权破解过期解决

    RAR registration data Federal Agency for Education 1000000 PC usage license UID=b621cca9a84bc5deffbf ...

  5. Mysql分页显示

    第一部分:看一下分页的基本原理:   mysql explain SELECT * FROM message ORDER BY id DESC LIMIT 10000, 20************* ...

  6. 如何让自己的广播只让指定的 app 接收?

    1.自己的应用(假设名称为应用 A)在发送广播的时候给自己发送的广播添加自定义权限,假设权限名为:com.itheima.android.permission , 然后需要在应用 A 的 Androi ...

  7. bzoj 2428: [HAOI2006]均分数据 && bzoj 3680 : 吊打XXX 模拟退火

    每次把元素随便扔随机一个初始解,退火时每次随机拿一个元素扔到随机一个集合里,当温度高时因为状态不稳定扔到那个元素和最小的里边. 如果新解优,更新ans. 把原式拆一下,就可以用int存了. bzoj ...

  8. List of NP-complete problems

    This is a list of some of the more commonly known problems that are NP-complete when expressed as de ...

  9. redis3.2装完后 其它机子访问爆protocol error, got 'n' as reply type byte

    服务器上装了reids3.2版本,配置文件中已将bind的选项注释掉, linux的iptables的redis端口也开放 其它机子的PHP访问redis爆“protocol error, got ' ...

  10. android studio 代码混淆如何忽略第三方jar包

    日前在打包混淆包含第三方jar包的Android studio项目时 报出了各种错误,但是debug版本却能正常运行,于是怀疑android studio 打包的时候把第三方jar包给混淆了,第三方j ...