C lang:Definition function
in parameter for show_n_char() is formal parameter
Aa_Definition function
#include <stdio.h>
#include <string.h>
#define NAME "ENOMOTHEM, INC."
#define ADDRESS "101 Beijing China"
#define PLACE "Megapolis, CA 00000"
#define WIDTH 40
#define WJXNUM 40
#define SPACE ' '
// function protype
void show_n_char(char ch, int num);
int main(void)
{
int spaces;
// function call
show_n_char('A',WJXNUM);
printf("\n");
putchar('\n');
show_n_char('*', WIDTH);
putchar('\n');
show_n_char(SPACE, 12);
printf("%s\n", NAME);
spaces = (WIDTH - strlen(ADDRESS)) / 2;
show_n_char(SPACE, spaces);
printf("%s\n", ADDRESS);
show_n_char(SPACE, (WIDTH - strlen(PLACE)) / 2);
printf("%s\n", PLACE);
show_n_char('*', WIDTH);
putchar('\n');
return 0;
}
//function definition
void show_n_char (char ch, int num)
{
int count;
for (count = 1; count <= num; count++)
putchar(ch);
}
Ab_Used return transport parameter What F*k
#include <stdio.h>
int imin(int, int);
int main(void)
{
int evil1, evil2;
printf("Enter a pair of integers (q to quit):\n");
while (scanf("%d %d", &evil1, &evil2) == 2)
{
printf("The lesser of %d and %d is %d.\n", evil1, evil2, imin(evil1, evil2));
printf("Enter a pair of integers (q to quit):\n");
}
printf("Bye.\n");
return 0;
}
int imin(int n, int m)
{
int min;
if (n < m)
min = n;
else
min = m;
return min;
}
Ac_Tail recursion and for relize factorial
Ac_a Factorial
- 0!=1
- 1×2×3×4×…×(n-2)×(n-1)×n=n!
#include <stdio.h>
long fact(int n);
long rfact(int n);
int main(void)
{
int num;
printf("This program calculatess factorials.\n");
printf("Enter a value in the range 0-12 (q to quit):\n");
while(scanf("%d", &num) == 1)
{
if (num < 0)
printf("No negative numbers, please.\n");
else if (num > 12)
printf("Keep input under 13.\n");
else
{
printf("loop: %d factorial = %ld\n", num, fact(num));
printf("recursion:%d factorial =%ld\n", num, rfact(num));
}
printf("Enter a value in the range 0-12 (q to quit):\n");
}
printf("Bye.\n");
return 0;
}
long fact(int n)
{
long ans;
for (ans = 1; n > 1; n--)
ans *= n;
return ans;
}
long rfact(int n)
{
long ans;
if (n > 0)
ans = n * rfact(n - 1);
else
ans = 1;
return ans;
}
Ad_recursion and inverted order
Ad_a Design algorithm
eg.
1. Oct 234
= 2x102+3x101+4x10^0
2. Bin 101
=1x22+0x21+1x2^0
3.5%3 = 2(1 to 2)
moda%b=a-(int)(a/b)*b
#include <stdio.h>
void to_binary(unsigned long n);
int main(void)
{
unsigned long number;
printf("Enter an integer (q to quit):\n");
while (scanf("%lu", &number) ==1)
{
printf("Binary equivalent:");
to_binary(number);
putchar('\n');
printf("Enter an integet (q to quit):\n");
}
return 0;
}
void to_binary(unsigned long n)
{
int r;
r =n % 2;
if (n >= 2)
to_binary(n /2);
putchar(r == 0 ? '0' : '1');
return;
}
C lang:Definition function的更多相关文章
- 2.13 Hive中自带Function使用及自定义UDF编程
UDF:User Definition Function 一.function #查看自带的函数 hive (db_hive)> show functions; #查看一个函数的详细用法 hiv ...
- [ES6系列-02]Arrow Function:Whats this?(箭头函数及它的this及其它)
[原创] 码路工人 大家好,这里是码路工人有力量,我是码路工人,你们是力量. 如果没用过CSharp的lambda 表达式,也没有了解过ES6,那第一眼看到这样代码什么感觉? /* eg.0 * fu ...
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- Moment.js学习(一)源代码
本篇主要是学习Moment.js.类库源代码如下: 2.4版本. //! moment.js //! version : 2.4.0 //! authors : Tim Wood, Iskren Ch ...
- Oracle Applications Multiple Organizations Access Control for Custom Code
档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...
- 【转】Build Your own Simplified AngularJS in 200 Lines of JavaScript
原文:http://blog.mgechev.com/2015/03/09/build-learn-your-own-light-lightweight-angularjs/ Build Your o ...
- bc - An arbitrary precision calculator language
bc(1) General Commands Manual bc(1) NAME bc - An arbitrary precision calculator language SYNTAX bc [ ...
- jQuery相关知识总结
1 encodeURIComponent(city)处理js传值乱码问题 2 总体概述 以后项目如果没有特殊情况,一般采用jQuery作为最基础的公共底层库. 另外对于前端的javascript相关的 ...
- jquery2.0.3 全部源码
/*! * Includes Sizzle.js 选择器,独立的库 * http://sizzlejs.com/ */ (function( window, undefined ) { //" ...
随机推荐
- ES6——async函数
目录 1.async 函数是 Generator 函数的语法糖. 2.async函数对 Generator 函数的改进,体现在以下四点. 3.基本用法 一个获取股票报价的函数 指定多少毫秒后输出一个值 ...
- jQuery操作元素对象的样式
在jQuery中操作元素为了加快速度,或者书写速度,可以用到json的格式: <!DOCTYPE html> <html> <head> <meta char ...
- Remember the Word (UVA-1402)
Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing ...
- 【搞定Jvm面试】 Java 内存区域揭秘附常见面试题解析
本文已经收录自笔者开源的 JavaGuide: https://github.com/Snailclimb ([Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识)如果觉得不错 ...
- ARTS-S pytorch中Conv2d函数padding和stride含义
padding是输入数据最边缘补0的个数,默认是0,即不补0. stride是进行一次卷积后,特征图滑动几格,默认是1,即滑动一格.
- JDBC导致的反序列化攻击
背景 上周BlackHat Europe 2019的议题<New Exploit Technique In Java Deserialization Attack>中提到了一个通过注入JD ...
- 一篇文章搞明白Integer、new Integer() 和 int 的概念与区别
基本概念的区分 1.Integer 是 int 的包装类,int 则是 java 的一种基本数据类型 2.Integer 变量必须实例化后才能使用,而int变量不需要 3.Integer 实际是对象的 ...
- flutter学习之环境配置
1.Android SDK通常目录: 用户->用户名->AppData->Local=>Android->Sdk 2.不知道的情况下,打开Android Studio,然 ...
- c++-多态的学习
多态的基本介绍 多态基础 面向对象新求 C++编译器提供的多态解决方案 多态意义.多态成立的是三个条件 多态理论基础 多态面试题强化 多态的理解 C++编译器如何实现多态 重载重写重定义 虚析构函数 ...
- Cesium 本地部署案例
众所周知,cesium的服务器是搭建在国外的,所以我们国内的用户访问的时候贼慢.有时想查个api或者看个案例半天都进不去,今天我来说一下傻瓜式搭建本地的cesium环境,用于大家没事查资料用!步骤:1 ...