掷骰子统计各个面出现的次数 调用函数实现 使用全局变量
来源:互联网 发布:sql和core data 编辑:程序博客网 时间:2024/05/22 13:43
#include <stdio.h>#include <stdlib.h>/* declaration and initialize globe variable */int FREQUENCY1 = 0;int FREQUENCY2 = 0;int FREQUENCY3 = 0;int FREQUENCY4 = 0;int FREQUENCY5 = 0;int FREQUENCY6 = 0;/* function prototype */int statistic(int);int main(){ int i_times;/* declaration the throw times */ int i_tmp;/* storage the result */ /* prompt */ printf("Enter the time of throw the dice: "); scanf("%d", &i_times); /* throw the dice */ while(i_times){ i_tmp = 1 + rand() % 6;/* 6 is the zoom factor, make sure the result between 0~5*/ statistic(i_tmp);/* call the function to statistic the frequency */ i_times--; } /* output the result */ printf("The 1 appear %d times;\n", FREQUENCY1); printf("The 2 appear %d times;\n", FREQUENCY2); printf("The 3 appear %d times;\n", FREQUENCY3); printf("The 4 appear %d times;\n", FREQUENCY4); printf("The 5 appear %d times;\n", FREQUENCY5); printf("The 6 appear %d times;\n", FREQUENCY6); return 0;}/* definition the function */int statistic(int result){ switch(result){ case 1: FREQUENCY1++; break; case 2: FREQUENCY2++; break; case 3: FREQUENCY3++; break; case 4: FREQUENCY4++; break; case 5: FREQUENCY5++; break; case 6: FREQUENCY6++; break; } return 0;}
0 0
- 掷骰子统计各个面出现的次数 调用函数实现 使用全局变量
- php 数组函数统计数组中,各个值出现的次数
- java实现统计输入一行string中统计其中各个字符出现的次数
- 实现给定一个字符串剔除重复字符,并统计各个字符出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 统计字符串中各个字符出现的次数
- 统计文本中各个字符出现的次数
- 统计文章内各个单词出现的次数
- 统计文章内各个单词出现的次数 (STL)
- python统计一个文档中 各个字符出现的次数
- C++统计英语句子中各个单词出现的次数
- java统计字符串中各个字符的出现次数
- 统计一串字符串中各个字符出现的次数
- 统计字符串中各个字符出现的次数
- 有序数组统计各个数字出现的次数
- Java中数组的复制
- 简单函数调用2
- 函数调用中的类型转换 c提升规则
- shell之Awk
- 掷骰子20次 统计结果
- 掷骰子统计各个面出现的次数 调用函数实现 使用全局变量
- 计算M的N次方
- 中国国家气象局天气预报信息接口代码引用详细说明与教程
- apache tomcat 6集群负载和session复制
- 几种常用算法思考
- Fibonacci
- APUE学习--信号(3)
- 读取系统时间作为seed 随机打印数字
- linux常用命令