C 语言实例 - 数值比较
C 语言教程
· 2019-02-20 15:29:28
比较两个数
以下实例中定义了两个整数变量,并使用 if 来比较两个数值,可以先看下逻辑图:
实例
#include <stdio.h>
int main() {
int a, b;
a = 11;
b = 99;
// 也可以通过以下代码实现让用户在终端输入两个数
// printf("输入第一个值:");
// scanf("%d", &a);
// printf("输入第二个值:");
// scanf("%d", &b);
if(a > b)
printf("a 大于 b");
else
printf("a 小于等于 b");
return 0;
}
输出结果:
a 小于等于 b
比较三个数
以下实例中定义了两个整数变量,并使用 if 来比较三个数值,可以先看下逻辑图:
实例
#include <stdio.h>
int main() {
int a, b, c;
a = 11;
b = 22;
c = 33;
if ( a > b && a > c )
printf("%d 最大", a);
else if ( b > a && b > c )
printf("%d 最大", b);
else if ( c > a && c > b )
printf("%d 最大", c);
else
printf("有两个或三个数值相等");
return 0;
}
输出结果:
33 最大
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
Numerical Recipes 3rd Edition
William H. Press、Saul A. Teukolsky、William T. Vetterling、Brian P. Flannery / Cambridge University Press / 2007-9-6 / GBP 64.99
Do you want easy access to the latest methods in scientific computing? This greatly expanded third edition of Numerical Recipes has it, with wider coverage than ever before, many new, expanded and upd......一起来看看 《Numerical Recipes 3rd Edition》 这本书的介绍吧!